Traits are a way of describing a 'contract' that a
struct must implement. Traits typically define method signatures but can also provide implementations based on other methods of the trait, providing the trait bounds allow for this.
For those familiar with object oriented programming, traits can be thought of as interfaces with some subtle differences.
Serde is a popular serialization and deserialization framework for Rust, used to convert serialized data (e.g. JSON and XML) to Rust structures and vice versa.
Serde supports many formats, including: JSON, YAML, TOML, BSON, Pickle and XML.
Rust Style Guide
Although there is no official Rust style guide, the following examples show the conventions adopted by most Rust projects. Following these conventions will align your project's style with that of the standard library, making it easier for people to see the logic in your code.
Unlike many other languages, Rust has two main string types:
String (a heap-allocated string type) and
&str (a borrowed string, which does not use extra memory). Knowing the difference and when to use each is vital to understand how Rust works.
Parallelism is supported well by Rust's standard library through various classes such as the
std::thread module, channels and atomics. This section will guide you through the usage of these types.
Cargo is Rust's package manager, used to manage crates (Rust's term for libraries/packages). Cargo predominantly fetches packages from crates.io and can manage complex dependency trees with specific version requirements (using semantic versioning). Cargo can also help build, run and manage Rust projects with
cargo run and
cargo test (among other useful commands).