Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Why do you need close contact Rust 1.0     - Delegate in C # (Programming)

- Build your own CA services: OpenSSL command line CA Quick Guide (Server)

- Comparison of Nginx and Nginx + (Server)

- Intrusion prevention network server security maintenance tips (Linux)

- Python Multithreaded Programming (Programming)

- Oracle: RETURNING clause (Database)

- Grub2 Boots the openSUSE installation image (Linux)

- Json data with double backslashes to a single backslash Json data processing (Programming)

- Use top to monitor the remote server (Server)

- Apache site default home page settings (Server)

- GitHub multiplayer co-development configuration (Linux)

- Ubuntu 14.04 compile RT288x_SDK / toolchain / squashfs3.2-r2 Error (Linux)

- Merge sort Java implementation (Programming)

- How to use OpenVPN and PrivacyIDEA build two-factor authentication for remote access (Server)

- Open container cluster management system architecture and components introduced Kubernetes (Server)

- SME Linux network security policy server security (Linux)

- Golang environment configuration recommendations (Linux)

- Oracle how to maintain the consistency of read? (Database)

- Git Advanced Tutorial (Linux)

- Install multiple Linux distributions and Fedora 21 first experience on the same hard disk (Linux)

 
         
  Why do you need close contact Rust 1.0
     
  Add Date : 2018-11-21      
         
         
         
  Without departing from the security or abstract, with a high operating efficiency, can prevent almost all errors, provide superior low-level control and performance - these are the commitments made Rust1.0 versions, and this is just the beginning .

After several years of iterative improvement, Rust programming language recently released version 1.0. As a modern language system, Rust from a large number whichever language (such as C / C ++) in essence, to its dregs, along with low-level control, high performance and powerful concurrency. To do this, Rust broke many of the traditional trade-offs, it provides:

Memory Security was no garbage collection
It did not have data concurrency competition
Zero overhead abstract
Stable and does not stagnate
No garbage collection

Software engineering, garbage collection is a powerful tool that lets you escape from the troubles in memory manually track and focus on writing better code. Although the garbage collector very good, it was not really appropriate in some areas, such as operating systems, embedded libraries and (soft) real-time applications, they usually require a greater degree of control and predictability, and the garbage collector can not provide these.

Rust allows developers to completely abandon the garbage collector, and will not face forget to release resources, dangling pointer, the risk of mistakes. Ownership (ownership) and borrowing (borrowing) is a key concept in Rust achieve these, the idea in programming everywhere, is also an important part of modern C ++. But is different from other languages, Rust put them in the heart of statically check and use them to ensure the safety of memory without a garbage collector, this is not imagine things before.

On ownership (Ownership), Rust idea is that each value can have only one owner (parent) to its complete control. As these values are reassigned or placed in the data structure passed to the function, and their ownership will be transferred can no longer be accessed through the original path. If it is beyond the scope (scope), ownership has not been transferred, it will be automatically destroyed. In order to make the operation of the right to a certain extent, Rust provides a range of values within the scope of temporary borrowing (pointer value) method.

Ownership not only replaces garbage collection, concurrency is also important to ensure, or even avoid such iterator invalidation of this type of bug. Rust is also applicable to other resources other than memory, such as when you close the socket, or file, you can be freed from the management.

Concurrency

As mentioned earlier, ownership also ensures that your data will not fall into concurrent program competition (data races) being hidden. The ownership will remain strong memory model, through hardware to close it.

Rust began with a concurrent program is very simple, through the standard library closures passed to the function:

Java code

use std :: thread;
fn main () {
    let some_string = "from the parent";
    thread :: spawn (move || {
        // Run on a new thread
        ! Println ( "printing a string {}", some_string);
    });
}

One of the principles of many concurrent programming language is shared state should be minimized or even completely banned, replaced by message passing, ownership means that the value of the default language Rust is only one owner, it will be sent to a new value through the channel guarantee thread original thread can not access it - static prohibit sharing.
However, messaging is only a tool in the toolbox, shared memory may also be useful. Type system to ensure that only thread-safe data can be shared between threads. For example, the standard library provides two types of reference counting: Arc provides thread safe A shared memory (default can not be changed), and Rc type can give up the need to ensure the security thread synchronization, provide a performance boost in the Arc. This type of system to ensure that no statically accidentally sent Rc value from one thread to another thread.

When you want to really want to change the memory, the ownership provides further assistance. Standard Library Mutex data type provides a type parameter, it can be protected by a lock. After ownership to ensure that this data only when holding the lock to access, but you can not unlock deliberately advance. This type of access control systems throughout the Rust and is widely used in its standard library.

Abstract zero cost performance and predictability is one of Rust's goal to achieve this goal is a very important step not only to ensure safety, but also to provide more powerful than C ++ at zero cost abstraction. Rust allows you to build a high level of abstraction, compile code for a specific database paradigm, avoid writing code for a variety of situations.

To do this, Rust precise control over memory layout, data can be placed directly on the stack or inline among other data structures, and heap allocation hosting less than most languages, it helps to get better cache locality, and this is an important element of modern hardware to improve performance.

This simple, straightforward layout of the data means that the optimizer can reliably eliminate function calls and types of layers, the high-level code is compiled to machine code efficient and predictable. Iterator is one prime example, the following code is a sequence of 32-bit integer square sum of conventional methods:

Java code

fn sum_squares (nums: & [i32]) -> i32 {
    nums.iter ()
        .map (| & x | x * x)
        .fold (0, | a, b | a + b)
}

On completion of the operation once the integer section, when optimization is turned on, even compiled into SIMD vector instructions.
Powerful type

Traditionally, functional programming languages provide similar algebraic data types, pattern matching, closures and flexible type inference function. Rust is one of many new development language, it is not directly applicable function model with these features, but combines them in a way - allowed without loss of performance applies a flexible application programming interfaces (APIs ).

Iterator examples above benefit from many of these ideas: this is entirely static typing, type inference means that unnecessary but those types stated. Closure is also essential, it allows simple write operation.

In most mainstream programming languages, algebraic data type is an enumeration (enums) an extension that allows a data type consists of a set of discrete selection of the composition, and each will choose Additional Information:

Java code

struct Point {
    x: f64,
    y: f64
}
enum Shape {
    Circle {
        center: Point,
        radius: f64
    },
    Rectangle {
        top_left: Point,
        bottom_right: Point
    },
    Triangle {
        a: Point,
        b: Point,
      c: Point
    }
}

Pattern matching is so easy to manipulate these types of key, if the shape is a value of type Shape, you can handle a variety of possibilities:

Java code

match shape {
    Shape :: Circle {radius, ..} => println! ( "Found a circle with radius {}",
radius),
    Shape :: Rectangle {top_left: tl, bottom_right: br} => {
        println! ( "found a rectangle from ({}, {}) to ({}, {})",
                tl.x, tl.y,
                br.x, br.y)
    }
    Shape :: Triangle {..} => println! ( "Found a triangle"),

The compiler can make sure that you address all situations (opt a catch-all clause), and to a great extent help reconstruction.
Enumeration (enums) also makes Rust prevention and treatment of so-called "multibillion dollar" Error: null reference (null references). The references in Rust is never empty, it allows you to select the type of a type-safe, localized mode selection nullability.

in conclusion

Rust is a sponsored by the Mozilla language that provides zero overhead abstract preserving C ++ performance, while for the web browser development, but also at the same time to ensure the safety and ease concurrent programming memory pressure.

Rust may fill a niche is considered to be impossible: in safety and without departing from the abstract to provide low-level control and performance. Of course, there is no free lunch, the compiler can not be tolerated as an assistant requires a little bit of risk, but still a little strange pattern of ownership, take some time to learn in the world.

1.0 version of the core language and libraries have been tested and refined over, and it is important for the stabilization of the guarantee: the compiled code should now also in the new version can be compiled in the future. Also, this version does not fulfill the language, Rust is using model trains, a new version every six weeks release a new and unstable characteristics may be by conventional pre-release versions betas and nightlies found. Currently, a standard package manager Cargo has been used to create a growing library system.

As languages, Rust ecology is not perfect, so that a broad package of tools and not as many older languages provided (although the latter a simple FFI helpful). Nevertheless, the language itself is powerful, and it is a tradition not dangerous, do low-level development good way.
     
         
         
         
  More:      
 
- Use Nginx as a load balancer (Server)
- To deploy MySQL database with separate read and write OneProxy (Database)
- Configuring ftp server and nfs server under Linux (Server)
- 7 JavaScript interview questions (Programming)
- RHEL6.4 x86_64 build SVN service (Server)
- Linux Powerful command Awk Introduction (Linux)
- Tomcat session clustering and server session (Server)
- CentOS 5.x install Lua 5.2.3 error (LIBS = -lncurses) (Linux)
- Linux / Windows setup is complete port range (Linux)
- ActionContext and ServletActionContext Summary (Programming)
- Use DB2 federated access Oracle (Database)
- Realization of Linux operating system illegal IP censorship (Linux)
- sudo command scenario analysis (Linux)
- How to customize your Linux desktop: Gnome 3 (Linux)
- Storm how to ensure that at least once semantics (Programming)
- Android official recommendation: DialogFragment create dialog (Programming)
- MySQL 5.7.10 source code for the latest version of the installation process in detail (Database)
- Manual cleaning Oracle audit records (Database)
- Oracle JDK installation under Ubuntu Linux (Linux)
- To install Python-Pip and Fabric under CentOS / Ubuntu (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.