All rights of books and documents belong to the authors, editors, and translators, the goal of this site is to facilitate reading.
If there is anything improper, please contact firstname.lastname@example.org.
##### The Hitchhiker's Guide to Rust Web
目前，仅是个人 Rust Web 开发中的一些记录。
涵盖：Rust Web 生态中的 Tide、actix-web、Yew、async-graphql、surf、handlebars-rust、rhai、jsonwebtoken，以及 mongodb 等。
The Rustonomicon is your guidebook to the dark arts of unsafe Rust. It’s also sometimes called “the ’nomicon.”
The Rustonomicon digs into all the awful details that you need to understand when writing Unsafe Rust programs.
Should you wish a long and happy career of writing Rust programs, you should turn back now and forget you ever saw this book. It is not necessary. However if you intend to write unsafe code — or just want to dig into the guts of the language — this book contains lots of useful information.
Unlike The Rust Programming Language, we will be assuming considerable prior knowledge. In particular, you should be comfortable with basic systems programming and Rust. If you don’t feel comfortable with these topics, you should consider reading The Book first. That said, we won’t assume you have read it, and we will take care to occasionally give a refresher on the basics where appropriate. You can skip straight to this book if you want; just know that we won’t be explaining everything from the ground up.
This book exists primarily as a high-level companion to The Reference. Where The Reference exists to detail the syntax and semantics of every part of the language, The Rustonomicon exists to describe how to use those pieces together, and the issues that you will have in doing so.
The Reference is not a formal spec, but is more detailed and comprehensive than the book.
This book is the primary reference for the Rust programming language. It provides three kinds of material:
- Chapters that informally describe each language construct and their use.
- Chapters that informally describe the memory model, concurrency model, runtime services, linkage model, and debugging facilities.
- Appendix chapters providing rationale and references to languages that influenced the design.
- This book is incomplete. Documenting everything takes a while.
- This document is not normative. It may include details that are specific to rustc itself, and should not be taken as a specification for the Rust language. We intend to produce such a document someday, but this is what we have for now.
This *Rust Cookbook*:
* Is a collection of simple examples;
* That demonstrate good practices to accomplish common programming tasks, using the crates of the Rust ecosystem.
[Read more about ](https://rust-cookbook.niqin.com/en-us/about.html)*[Rust Cookbook](https://rust-cookbook.niqin.com/en-us/about.html)*, including tips for how to read the book, how to use the examples, and notes on conventions.
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.
Rust by Example (RBE) is a collection of runnable examples that illustrate various Rust concepts and standard libraries. To get even more out of these examples, don't forget to install Rust locally and check out the official docs. Additionally for the curious, you can also check out the source code for this site.
Now let's begin!
* Hello World - Start with a traditional Hello World program.
* Primitives - Learn about signed integers, unsigned integers and other primitives.
* Custom Types - struct and enum.
* Variable Bindings - mutable bindings, scope, shadowing.
* Types - Learn about changing and defining types.
* Flow of Control - if/else, for, and others.
* Functions - Learn about Methods, Closures and High Order Functions.
* Modules - Organize code using modules
* Crates - A crate is a compilation unit in Rust. Learn to create a library.
* Cargo - Go through some basic features of the official Rust package management tool.
* Attributes - An attribute is metadata applied to some module, crate or item.
* Generics - Learn about writing a function or data type which can work for multiple types of arguments.
* Scoping rules - Scopes play an important part in ownership, borrowing, and lifetimes.
* Traits - A trait is a collection of methods defined for an unknown type: Self
* Error handling - Learn Rust way of handling failures.
* Std library types - Learn about some custom types provided by std library.
* Std misc - More custom types for file handling, threads.
* Testing - All sorts of testing in Rust.
* Unsafe Operations
* Meta - Documentation, Benchmarking.
It wasn’t always so clear, but the Rust programming language is fundamentally about empowerment: no matter what kind of code you are writing now, Rust empowers you to reach farther, to program with confidence in a wider variety of domains than you did before.
Take, for example, “systems-level” work that deals with low-level details of memory management, data representation, and concurrency. Traditionally, this realm of programming is seen as arcane, accessible only to a select few who have devoted the necessary years learning to avoid its infamous pitfalls. And even those who practice it do so with caution, lest their code be open to exploits, crashes, or corruption.
Rust breaks down these barriers by eliminating the old pitfalls and providing a friendly, polished set of tools to help you along the way. Programmers who need to “dip down” into lower-level control can do so with Rust, without taking on the customary risk of crashes or security holes, and without having to learn the fine points of a fickle toolchain. Better yet, the language is designed to guide you naturally towards reliable code that is efficient in terms of speed and memory usage.
Programmers who are already working with low-level code can use Rust to raise their ambitions. For example, introducing parallelism in Rust is a relatively low-risk operation: the compiler will catch the classical mistakes for you. And you can tackle more aggressive optimizations in your code with the confidence that you won’t accidentally introduce crashes or vulnerabilities.
But Rust isn’t limited to low-level systems programming. It’s expressive and ergonomic enough to make CLI apps, web servers, and many other kinds of code quite pleasant to write — you’ll find simple examples of both later in the book. Working with Rust allows you to build skills that transfer from one domain to another; you can learn Rust by writing a web app, then apply those same skills to target your Raspberry Pi.
This book fully embraces the potential of Rust to empower its users. It’s a friendly and approachable text intended to help you level up not just your knowledge of Rust, but also your reach and confidence as a programmer in general. So dive in, get ready to learn—and welcome to the Rust community!
— Nicholas Matsakis and Aaron Turon