Cargo
Behavior: By default,
cargo build
looks at the files in yoursrc
directory and figures out what to build. When it seessrc/lib.rs
, it knows that it needs to build a library.
Behavior: Cargo will automatically compile files inside
src/bin
when you runcargo build
. The executables created from the files insrc/bin
can be run usingcargo run --bin my_bin
.
Useful Commands
Command | Result |
---|---|
rustup update | Updates Rust |
cargo new --bin <package_name> | Creates a new package |
cargo package --list | List all files included in a package |
cargo doc --no-deps --open | Create 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.