Tristan Hume

Github Resume + Project List Blog

Tristan’s Top 100 Rust Crates

Based on a talk I gave at the Bay Area Rust Meetup in October 2018.

Command Line: Better existing commands

Command Line: New(ish) powers

Web: Static

Web: Backend

Web: Frontend

Web: Templating

Async I/O

Graphics & Games

2D Graphics

GUI

Extending other languages

Example: helix

ruby! {
    class Console {
        def log(string: String) {
            println!("LOG: {}", string);
        }
    }
}

OS Interface

Command line output

Command line arguments

Example: structopt

/// A basic example
#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
struct Opt {
    /// Activate debug mode
    #[structopt(short = "d", long = "debug")]
    debug: bool,
    /// Set speed
    #[structopt(short = "s", long = "speed", default_value = "42")]
    speed: f64,
    /// Number of cars
    #[structopt(short = "c", long = "nb-cars")]
    nb_cars: Option<i32>,
}

fn main() {
    let opt = Opt::from_args();
    println!("{:?}", opt);
}

Utility libraries

Example: failure

#[derive(Debug, Fail)]
enum ToolchainError {
    #[fail(display = "invalid toolchain name: {}", name)]
    InvalidToolchainName { name: String },
    #[fail(display = "unknown toolchain version: {}", version)]
    UnknownToolchainVersion { version: String }
}

pub fn read_toolchains(path: PathBuf) -> Result<Toolchains, Error> {
  // ... can use ? on ToolchainError, io Error and other errors
}

Example: lazy_static

lazy_static! {
    static ref HASHMAP: HashMap<u32, &'static str> = {
        let mut m = HashMap::new();
        m.insert(0, "foo");
        m
    };
}

fn main() {
    println!("`0` is \"{}\".", HASHMAP.get(&0).unwrap());
}

Example: bitflags

bitflags! {
    struct Flags: u32 {
        const A = 0b00000001;
        const B = 0b00000010;
        const C = 0b00000100;
        const ABC = Self::A.bits | Self::B.bits | Self::C.bits;
    }
}

fn main() {
    let e1 = Flags::A | Flags::C;
    let e2 = Flags::B | Flags::C;
    assert_eq!((e1 | e2), Flags::ABC);   // union
    assert_eq!((e1 & e2), Flags::C);     // intersection
    assert_eq!((e1 - e2), Flags::A);     // set difference
    assert_eq!(!e2, Flags::A);           // set complement
}

Text processing

Algorithms & Data structure utilities

Cargo addons

Testing

Property Testing

Example: Property testing

#[macro_use] extern crate quickcheck;
quickcheck! {
  fn prop(xs: Vec<u32>) -> bool {
      xs == reverse(&reverse(&xs))
  }
}

#[macro_use] extern crate proptest;
proptest! {
    #[test]
    fn parses_all_valid_dates(ref s in "[0-9]{4}-[0-9]{2}-[0-9]{2}") {
        parse_date(s).unwrap();
    }
}

Optimizing

Vector math

Parallelizing

Example: rayon

use rayon::prelude::*;
fn sum_of_squares(input: &[i32]) -> i32 {
    input.par_iter() // <-- just change that!
         .map(|&i| i * i)
         .sum()
}

Example: faster

use faster::*;
let lots_of_3s = (&[-123.456f32; 128][..]).simd_iter()
    .simd_map(f32s(0.0), |v| {
        f32s(9.0) * v.abs().sqrt().rsqrt().ceil().sqrt() - f32s(4.0) - f32s(2.0)
    })
    .scalar_collect();

Serialization

Example: serde

#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;

#[derive(Serialize, Deserialize, Debug)]
struct Point { x: i32, y: i32 }

fn main() {
    let point = Point { x: 1, y: 2 };
    let serialized = serde_json::to_string(&point).unwrap();
    let deserialized: Point = serde_json::from_str(&serialized).unwrap();
    println!("ser = {}, de = {:?}", serialized, deserialized);
}

Parsing and compiling

Other