Introduce
Official web sites:
- h
- h
- h
- h
- h
Unofficial web sites:
- h
Rust 是一个系统级编程语言,Rust 最早是由 Mozilla 工程师 Graydon Hoare(https://github.com/graydon) 于 2006 年开始开发的。后来提交给了 Mozilla ,2010年对外公布过 0.1.0 版本,最早由 Ocmal 语言编写。他形容 Rust 是一种线程安全的支持并发的实用型的编程语言,支持函数式编程与命令式编程。
Rust 是一门强调安全、性能和并发性的系统编程语言。它为了达到这几个目的,甚至没有一个垃圾收集器。这也使 Rust 能够应用到其他语言做不到的地方:嵌入到其他语言,有指定空间和时间需求的程序,写底层代码(如设备驱动程序和操作系统)。针对当前的其他编程语言,Rust 做到了没有运行时(Runtime),没有数据竞争。 Rust 也致力于实现“零成本抽象”,尽管这些抽象给人的感觉像一个高级的语言。即使是这样,Rust 仍然可以做到像一个低级的语言那样的精确控制。
从 2016 年 至 2022 年,连续 7 年 Stack Overflow 开发人员调查中,Rust 被评比为 “最受欢迎的编程语言” 之一。
首个 Rust 编译器 叫做 rustboot,始于 2010 年,是用 OCaml 编写的,它最终目的是被用于构建第二个由 Rust 实现的编译器 rustc,并由此开启了 Rust 自举的历程。除了基于 Rust 编写之外,rustc 还使用了 LLVM 作为后端来生成机器代码,来代替之前 rustboot 的手写 x86 代码生成器。Rust 第一次自举构建是在 2011 年 4 月 20 日。该过程总共花了一个小时。
Why is it called “Rust”?
TL;DR: Rust is named after a fungus that is robust, distributed, and parallel.
Also, calling Rust a research language is funny to me because – as its name reflects – we've tried hard to avoid incorporating new technology into it. We haven't always succeeded at failing to be novel, but we have a rule of thumb of not including any ideas in the language that are new as of the past ten years of programming language research. The field of programming language is full of old technology that hasn't been put to use in solving problems that it's exactly suited for. The goals with Rust were to avoid reinventing wheels, and see what the past had to teach us. I can't blame anyone for thinking Rust is a research language, though, since it is being developed by Mozilla Research.
核心设计原则
Rust 的核心设计原则:
- 实用性(Practicality) :它应该是一种可以在现实世界中使用的语言;
- 务实(Pragmatism):它应该是符合人性化体验,并且能与现有系统方便集成的语言;
- 内存安全性(Memory-safety) :它必须加强内存安全,不允许出现段错误和其他类似的内存访问违规操作;
- 高性能(Performance) :它必须拥有能和 C++ 比肩的性能;
- 高并发(Concurrency) :它必须为编写并发代码提供现代化的解决方案。
Foundation
https://foundation.rust-lang.org/ - Rust Foundation
Members: AWS, Google, Huawei, Microsoft, Mozilla
Rust 基金会的目的是使 Rust 维护人员可以快乐地把工作做到最好。Rust 核心团队相信最好的Rust 将由快乐者维护,将基金会的工作重点放在维护者身上,将为所有人提供更好的 Rust。
Why Rust?
高性能
Rust 速度惊人且内存利用率极高。由于没有运行时和垃圾回收,它能够胜任对性能要求特别高的服务,可以在嵌入式设备上运行,还能轻松和其他语言集成。
可靠性
Rust 丰富的类型系统和所有权模型保证了内存安全和线程安全,让您在编译期就能够消除各种各样的错误。
生产力
Rust 拥有出色的文档、友好的编译器和清晰的错误提示信息, 还集成了一流的工具 —— 包管理器和构建工具, 智能地自动补全和类型检验的多编辑器支持, 以及自动格式化代码等等。
Pros
- a uniform compiler from Rust developers with a built-in package builder and manager, test system and documentation generator
- Safe memory management that helps to avoid segmentation errors
- An ability to use abstractions, which makes manual memory control easier
- Fix suggestions for most common compile errors, plus clear and concise pattern errors
- Pointers could only be used in unsafe code – safe code only includes links to objects guaranteed to exist
- Great compatibility with Mac and Unix-like systems
Cons
- Lack of classes and succession, which makes writing object-oriented code harder
- Very strict compiler that sometimes polices memory addresses too much
Installation
Online Installation
Official site: https://rustup.rs/, install:
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Update Rust:
$ rustup update stable
Rustup Mirror:
export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"
curl --proto '=https' --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh
~/.cargo/config
config:
[source.crates-io]
replace-with = 'rsproxy-sparse'
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"
[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"
[net]
git-fetch-with-cli = true
Offline Installation
Other Rust Installation Methods:
h
QuickStart
Play Rust Online
Just open h
t or ht p s : / / p l a y . r u s t - l a n g . o r g / t t p s : / / p l a y . i n t e g e r 3 2 . c o m /
Compile with Rustc
Edit file:
% vi helloworld.rs
fn main() {
println!("Hello world!");
}
Compile:
% rustc helloworld.rs
Run:
% ./helloworld
Hello world!
Create Project with Cargo
New project:
% cargo new helloworld
% cd helloworld
Edit file:
% vi src/main.rs
fn main() {
println!("Hello world!");
}
Build:
% cargo build
Run:
% ./target/debug/helloworld
Hello world!
Install Crates with Cargo
Cargo install can install many tools registered on crates.io
, like:
$ cargo install just
More tools: h
Check Code with Cargo
Check a local package and all of its dependencies for errors
% cargo check
Lint Code with Cargo
Checks a package to catch common mistakes and improve your Rust code.
% cargo clippy
Learn Rust
Course for Rust learner from Microsoft:
IDE
- i
- v
- v
- e
See more: h
t t p s : / / a r e w e i d e y e t . c o m /
Resources
Read books, please click Rust Books
Rustup doc
Cargo docs:
$ cargo doc --open
Show Rust docs:
$ rustup doc [--book]
--alloc The Rust core allocation and collections library
--book The Rust Programming Language book
--cargo The Cargo Book
--core The Rust Core Library
--edition-guide The Rust Edition Guide
--embedded-book The Embedded Rust Book
--nomicon The Dark Arts of Advanced and Unsafe Rust Programming
--path Only print the path to the documentation
--proc_macro A support library for macro authors when defining new macros
--reference The Rust Reference
--rust-by-example A collection of runnable examples that illustrate various Rust concepts and standard libraries
--rustc The compiler for the Rust programming language
--rustdoc Generate documentation for Rust projects
--std Standard library API documentation
--test Support code for rustc's built in unit-test and micro-benchmarking framework
--unstable-book The Unstable Book
Online Study
https://tourofrust.com/ - Tour of Rust - Hello, Rust
Algorithms
h
h
Other
h
h
h
h
h
h
h
Awesome
h
h
h
h
h
h
h
h
https://cryptography.rs/ - Awesome Rust Cryptography[GitHub]
h
h
h
h
h
h
h
Crates
- https://crates.io/ - Crates.io
- https://docs.rs/ - Docs.rs
- https://lib.rs/ - Lib.rs
Goto Rust Crates
Integrate
h
Can I use
h
Are we * yet?
- h
- h
- h
- h
- h
- h
- h
h
t - Areweyett p s : / / w i k i . m o z i l l a . o r g / A r e w e y e t
WebAssembly
JavaScript Web 应用程序很难获得,并保持可靠的性能。JavaScript 的动态类型系统和垃圾回收暂停没有帮助。如果您不小心徘徊在 JIT 的快乐路径上,看似很小的代码更改可能导致严重的性能退化。
Rust 为程序员提供了低层控制和可靠的性能。它不受 JavaScript 的非确定性垃圾收集暂停的影响。程序员可以以间接,单态化和内存布局,去控制。
WASM projects: h
WASM Github groups:
- h
- h
- h
Learn more: h
Forum
https://rustcc.cn/ - Rust语言中文社区
https://learnku.com/rust - Rust 技术论坛 | Rust 语言技术论坛 - 优质的 Rust 开发者学习社区
Whos is using Rust?
- PingCAP(TiKV)
- Facebook(version control)
- Dropbox
- Firefox
- Discord
- Linkerd
- Google(fuschia)
- Microsoft(windows-rs)
- AWS(Firecracker)
- Huawei(C2Rust)
Official list: Production users
Thirdparty company list: ht t p s : / / g i t h u b . c o m / o m a r a b i d / r u s t - c o m p a n i e s
Projects
Announcing KataOS and Sparrow - To prove-out a secure ambient system in its entirety, we're also building a reference implementation for KataOS called Sparrow, which combines KataOS with a secured hardware platform.
https://deno.land/ - Deno[GitHub]
https://www.diem.com/ - Diem[GitHub]
https://tikv.org/ - TiKV[GitHub]
https://github.com/cswinter/LocustDB - LocustDB
https://teaclave.apache.org/ - Apache Teaclave (Incubating)[GitHub]
https://www.redox-os.org/ - OS written in Rust[GitLab]
https://www.tockos.org/ - TockOS[GitHub]
https://firecracker-microvm.github.io/ - Firecracker[Github]
https://fuchsia.dev/ - Fuchsia
h
h
Trending
- h
t - Trending Rust Projectst p s : / / w w w . l i b h u n t . c o m / l / r u s t / t r e n d i n g
*.cli.rs
Create your *.cli.rs
web site, access https://cli.rs/ [GitHub]
Code Standard
https://rust-coding-guidelines.github.io/rust-coding-guidelines-zh/index.html - RustCodingGuidelines [GitHub]
Secure Code
h
h
Other implementions
h
h
h
h
Advanced
https://github.com/rustcc/writing-an-os-in-rust - 《使用Rust编写操作系统》
Rust for X
Rust for {Ruby, Haskell, C, …} programmers
h
Rust for JS Developers
h
Rust for Java Developers
Rust for Java Developers @YouTube
FAQ
h
Jobs
h
Reference
h
h
h
h
h
h
h
h
h