rust 介绍 some tools install development environment Ownership

website
crates
Version 1.33

提供了内存安全和可靠的并发

这一杀手级的特性就是 ownership, moves, and borrows

IDE 目前使用 Clion + rust plugin

Rust is a modern systems programming language focusing on safety, speed, and concurrency. It accomplishes these goals by being memory safe without using garbage collection.

Performance

Rust is blazingly fast and memory-efficient: with no runtime or garbage collector, it can power performance-critical services, run on embedded devices, and easily integrate with other languages.

Reliability

Rust’s rich type system and ownership model guarantee memory-safety and thread-safety — and enable you to eliminate many classes of bugs at compile-time.

Productivity

Rust has great documentation, a friendly compiler with useful error messages, and top-notch tooling — an integrated package manager and build tool, smart multi-editor support with auto-completion and type inspections, an auto-formatter, and more.

some tools

  • cargo: Rust’s compilation manager, package manager, and general-purpose tool
  • rustc:Rust compiler. Usually we let Cargo invoke the compiler for us
  • rustdoc:rustdoc can build nicely formatted HTML for us.

install development environment

rustup

execute in command-line curl https://sh.rustup.rs -sSf | sh

encountered this error.

1
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to sh.rustup.rs:443

solution:
take a rest, buy a cup of coffee. and try again a few hours later.
maybe 18.00 is ok

add the following line to your ~/.bash_profile:

1
export PATH="$HOME/.cargo/bin:$PATH"

Cargo: the Rust build tool and package manager

  • build your project with cargo build
  • run your project with cargo run
  • test your project with cargo test
  • build documentation for your project with cargo doc
  • publish a library to crates.io with cargo publish

To test that you have Rust and Cargo installed, you can run this in your terminal of choice:
cargo --version

You can install a code formatting tool (Rustfmt) with rustup component add rustfmt,
and a linting tool (Clippy) with rustup component add clippy.

need update rustup update
need uninstall rustup self uninstall

Ownership

Ownership is Rust’s most unique feature, and it enables Rust to make memory safety guarantees without needing a garbage collector.
related features: borrowing, slices
Rust uses a third approach: memory is managed through a system of ownership with a set of rules that the compiler checks at compile time. None of the ownership features slow down your program while it’s running.

Rules

  • Each value in Rust has a variable that’s called its owner.
  • There can only be one owner at a time.
  • When the owner goes out of scope, the value will be dropped.