Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

stdx

> 编程语言
Open source

The missing batteries of Rust

2.1K stars0 likes0 views
WebsiteGitHub

About

The missing batteries of Rust

This project is unmaintained. For a similar project see rustmax.

stdx - The missing batteries of Rust

New to Rust and don't yet know what crates to use? stdx has the best crates.

Current revision: stdx 0.119.0-rc, for Rust 1.19, July 20, 2017.

Feature Crate
Bitfields [bitflags = "0.9.1"] [][d-bitflags]
Byte order conversion [byteorder = "1.1.0"] [][d-byteorder]
Date and time [chrono = "0.4.0"] [][d-chrono]
Command-line argument parsing [clap = "2.25.0"] [][d-clap]
Encoding/decoding [encoding_rs = "0.6.11"] [][d-encoding_rs]
Error handling [error-chain = "0.10.0"] [][d-error-chain]
Fast hashing [fnv = "1.0.5"] [][d-fnv]
Compression - deflate (gzip) [flate2 = "0.2.19"] [][d-flate2]
Iterator functions, macros [itertools = "0.6.0"] [][d-itertools]
Global initialization [lazy_static = "0.2.8"] [][d-lazy_static]
C interop [libc = "0.2.25"] [][d-libc]
Logging [log = "0.3.8"] [][d-log]
Memory-mapped file I/O [memmap = "0.5.2"] [][d-memmap]
Multidimensional arrays [ndarray = "0.9.1"] [][d-ndarray]
Big, rational, complex numbers [num = "0.1.40"] [][d-num]
Number of CPUs [num_cpus = "1.6.2"] [][d-num_cpus]
Random numbers [rand = "0.3.15"] [][d-rand]
Parallel iteration [rayon = "0.8.2"] [][d-rayon]
Regular expressions [regex = "0.2.2"] [][d-regex]
HTTP client [reqwest = "0.7.1"] [][d-reqwest]
Software versioning [semver = "0.7.0"] [][d-semver]
Serialization [serde = "1.0.10"] [][d-serde]
JSON [serde_json = "1.0.2"] [][d-serde_json]
Tar archives [tar = "0.4.23"] [][d-tar]
Temporary directories [tempdir = "0.3.5"] [][d-tempdir]
Thread pool [threadpool = "1.4.0"] [][d-threadpool]
Configuration files [toml = "0.4.2"] [][d-toml]
URLs [url = "1.5.1"] [][d-url]
Directory traversal [walkdir = "1.0.7"] [][d-walkdir]

     

bitflags = "0.9.1"   [][d-bitflags]

The only thing this crate does is export the [bitflags!] macro, but it's a heckuva-useful macro. bitflags! produces typesafe bitmasks, types with named values that are efficiently packed together as bits to express sets of options.

Example: [examples/bitflags.rs]

…

     

byteorder = "1.1.0"   [][d-byteorder]

When serializing integers it's important to consider that not all computers store in memory the individual bytes of the number in the same order. The choice of byte order is called ["endianness"], and this simple crate provides the crucial functions for converting between numbers and bytes, in little-endian, or big-endian orders.

Example: [examples/byteorder.rs]

…

     

chrono = "0.4.0"   [][d-chrono]

Date and time types.

Example: [examples/chrono.rs]

extern crate chrono;
use chrono::*;

fn main() {
    let local: DateTime<Local> = Local::now();
    let utc: DateTime<Utc> = Utc::now();

    let dt = Utc.ymd(2014, 11, 28).and_hms(12, 0, 9);

    assert_eq!((dt.year(), dt.month(), dt.day()), (2014, 11, 28));
    assert_eq!((dt.hour(), dt.minute(), dt.second()), (12, 0, 9));

    assert_eq!(dt.format("%Y-%m-%d %H:%M:%S").to_string(), "2014-11-28 12:00:09");
    assert_eq!(dt.format("%a %b %e %T %Y").to_string(), "Fri Nov 28 12:00:09 2014");

    assert_eq!(format!("{}", dt), "2014-11-28 12:00:09 UTC");
}

     

clap = "2.25.0"   [][d-clap]

Clap is a command line argument parser that is easy to use and is highly configurable.

Example: [examples/clap.rs]

…

Alternatives: [docopt]

     

encoding_rs = "0.6.11"   [][d-encoding_rs]

encoding_rs is a Gecko-oriented Free Software / Open Source implementation of the Encoding Standard in Rust. Gecko-oriented means that converting to and from UTF-16 is supported in addition to converting to and from UTF-8, that the performance and streamability goals are browser-oriented, and that FFI-friendliness is a goal.

Example: [examples/encoding_rs.rs]

extern crate encoding_rs;
use encoding_rs::*;

fn main() {
    let expected = "\\u{30CF}\\u{30ED}\\u{30FC}\\u{30FB}\\u{30EF}\\u{30FC}\\u{30EB}\\u{30C9}";
    let encoded = b"\x83n\x83\x8D\x81[\x81E\x83\x8F\x81[\x83\x8B\x83h";

    let (decoded, encoding_used, had_errors) = SHIFT_JIS.decode(encoded);

    assert_eq!(&decoded[..], expected);
    assert_eq!(encoding_used, SHIFT_JIS);
    assert!(!had_errors);

    println!("Decoded result: {}", decoded);
}

     

error-chain = "0.10.0"   [][d-error-chain]

Rust programs that handle errors consistently are reliable programs. Even after one understands [error handling] in Rust, it can be difficult to grasp and implement its best practices. error-chain helps you define your own error type that works with the ? operator to make error handling in Rust simple and elegant.

Example: [examples/error-chain.rs]

…

Alternatives: [quick-error]

     

flate2 = "0.2.19"   [][d-flate2]

Compression and decompression using the [DEFLATE] algorithm.

Example: [examples/flate2.rs]

…

     

fnv = "1.0.5"   [][d-fnv]

The standard library's hash maps are notoriously slow for small keys (like integers). That's because they provide strong protection against a class of denial-of-service attacks called ["hash flooding"]. And that's a reasonable default. But when your HashMaps are a bottleneck consider reaching for this crate. It provides the Fowler-Noll-Vo hash function, and conveniences for creating FNV hash maps that are considerably faster than those in std.

Example: [examples/fnv.rs]

extern crate fnv;

use fnv::FnvHashMap;

fn main() {
    let mut map = FnvHashMap::default();
    map.insert(1, "one");
    map.insert(2, "two");
    map.insert(3, "three");

    for (number, word) in map.iter() {
        println!("Number {}: {}", number, word);
    }

    map.remove(&(2));
    println!("The length of HashMap is {}.", map.len());
    println!("The first element is {}.", map.get(&(1)).unwrap());
}

     

itertools = "0.6.0"   [][d-itertools]

The Rust standard [Iterator] type provides a powerful abstraction for operating over sequences of values, and is used pervasively throughout Rust. There are though a number of common operations one might want to perform on sequences that are not provided by the standard library, and that's where itertools comes in. This crate has everything including the kitchen sink (in the form of the [batching] adaptor). Highlights include [dedup], [group_by], [mend_slices], [merge], [sorted], [join] and more.

Example: [examples/itertools.rs]

extern crate itertools;

use itertools::{join, max, sorted};

fn main(){
    let a = [3, 2, 5, 8, 7];

    // Combine all iterator elements into one String,
    // seperated by *.
    println!("{:?}", join(&a, "*"));
    // Return the maximum value of the iterable.
    println!("{:?}", max(a.iter()).unwrap());
    // Collect all the iterable's elements into a
    // sorted vector in ascending order.
    println!("{:?}", sorted(a.iter()));
}

     

lazy_static = "0.2.8"   [][d-lazy_static]

Rust has strict rules about accessing global state. In particular there is no ['life before main'] in Rust, so it's not possible to write a programmatic constructor for a global value that will be run at startup. Instead, Rust prefers lazy execution for global initialization, and the lazy_static! macro does just that.

Example: [examples/lazy_static.rs]

…

     

libc = "0.2.25"   [][d-libc]

If you need to talk to foreign code, you need this crate. It exports C type and function definitions appropriate to each target platform Rust supports. It defines the standardized C features that are common across all platforms as well as non-standard features specific to the platform C libraries. For more platform-specific FFI definitions see [nix] and [winapi].

Example: [examples/libc.rs]

extern crate libc;

fn main() {
    unsafe {
        libc::exit(0);
    }
}

     

log = "0.3.8"   [][d-log]

The most common way to perform basic logging in Rust, with the [error!], [warn!], [info!], and [debug!] macros. It is often combined with the [env_logger] crate to get logging to the console, controlled by the [RUST_LOG] environment variable. This is the traditional logging crate used by rustc, and its functionality was once built in to the language.

Supplemental crates: [env_logger = "0.4.3"]

Example: [examples/log.rs]

#[macro_use]
extern crate log;
extern crate env_logger;

use log::LogLevel;

fn main() {
    env_logger::init().unwrap();

    debug!("this is a debug {}", "message");
    error!("this is printed by default");

    if log_enabled!(LogLevel::Info) {
        let x = 3 * 4; // expensive computation
        info!("the answer was: {}", x);
    }
}

Alternatives: [slog], [log4rs]

     

memmap = "0.5.2"   [][d-memmap]

Cross-platform access to [memory-mapped I/O], a technique for sharing memory between processes, and for accessing the content of files as a simple array of bytes. It is implemented by binding the [mmap] syscall on Unix, and the [CreateFileMapping] / [MapViewOfFile] functions on Windows. This is a low-level feature used to build other abstractions. Note that it's not generally possible to create safe abstractions for memory mapping, since memory mapping entails shared access to resources outside of Rust's control. As such, the APIs in this crate are unsafe.

Example: examples/memmap.rs

extern crate memmap;

use memmap::{Mmap, Protection};
use std::env;
use std::io;
use std::str;

fn run() -> Result<(), io::Error> {
    let mut args = env::args().skip(1);
    let input = args.next().expect("incorrect argument");

    let map = Mmap::open_path(input, Protection::Read)?;
    unsafe {
        let all_bytes = map.as_

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rust

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言