Cargo

Behavior: By default, cargo build looks at the files in your src directory and figures out what to build. When it sees src/lib.rs, it knows that it needs to build a library.

Behavior: Cargo will automatically compile files inside src/bin when you run cargo build. The executables created from the files in src/bin can be run using cargo run --bin my_bin.

Useful Commands

CommandResult
rustup updateUpdates Rust
cargo new --bin <package_name>Creates a new package
cargo package --listList all files included in a package
cargo doc --no-deps --openCreate HTML documentation for your project; the output gets saved to target/doc

Rust Tools

Automatic code formatting

$ rustup component add rustfmt-preview

Installs both rustfmt for formatting rust, and cargo-fmt for formatting Cargo configurations.

Run it with $ cargo fmt

Automatic code fixing and version migrations

Run rustfix with: $ cargo fix

Automatc code improvements

$ rustup component add clippy-preview

Install clippy.

Run it with: $ cargo clippy

Common Profile Settings

debug

Controls the -g option sent to rustc, which turns debug symbols on and off. Possible values: true | false

Links

Recommended Creates

Binary Data, Compression, and Serialization

byteorder

Offers traits that add methods to all readers and writers for binary input and output.

flate2

Provides adapter methods for reading and writing gzipped data.

serde

Used for serialization; it converts back and forth between Rust structs and bytes.

Networking

mio

Support for asynchronous input and output to create high-performance servers. It provides a simple event loop and asynchronous methods for reading, writing, connecting, and accepting connections. (basically an asynchronous copy of the whole networking API)

tokio

Wraps the mio event loop in a futures-based API.

reqwest

Provides a beautiful API for HTTP clients.

iron

Higher-level server framework with support for things like middleware traits.

websocket

Implements the WebSocket protocol.