2.16 Additional Topics

2.16.1 The Standard Library

  • Rust's standard library provides common functionality, similar to C's standard library (libc).
  • Includes data structures like Vec, HashMap, and utilities for I/O, threading, and more.

2.16.2 Testing

  • Rust has built-in support for unit tests using the #[test] attribute.
#[cfg(test)]
mod tests {
    #[test]
    fn test_add() {
        assert_eq!(2 + 2, 4);
    }
}

2.16.3 Cargo Features

  • Building: cargo build
  • Running: cargo run
  • Testing: cargo test
  • Documentation: cargo doc --open

2.16.4 Error Messages and Tooling

  • Rust provides detailed compiler error messages to help you fix issues.
  • Tools like rustc (the compiler) and clippy (a linter) assist in writing idiomatic Rust code.