7

Crate List - Blessed.rs

 1 year ago
source link: https://blessed.rs/crates
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

What is blessed.rs?

Compared to other programming languages such as Python and Go, Rust's standard library is very small, including only core data structures in the standard library with all other functionality farmed out to 3rd party ecosystem crates, and a common complaint from new Rust developers is that they don't know where to start: which crates they ought to use and which crates they ought to trust.

This list attempts to answer those questions.

Common

Very commonly used crates that everyone should know about

General

General purpose

Use Case Recommended Crates
Random numbers

rand
De facto random number generation library split out from the standard library

UUIDs

uuid
Implements generating and parsing UUIDs and a number of utility functions

Serialization (JSON, YAML, etc)

serde
De facto serialization library. Use in conjunction with sub-crates like serde_json for the specific format that you are using.

Regular Expressions

regex
De facto regex library. Very fast, but does not support fancier features such as backtracking.

fancy_regex
Use if need features such as backtracking which regex doesn't support

Temporary files

tempfile
Supports both temporary files and temporary directories

Gzip (de)compression

flate2
Uses a pure-Rust implementation by default. Use feature flags to opt in to system zlib.

Time & Date

time
The original datetime crate which was split out of std pre-rust-1.0. Preferrable if covers your needs, but it's quite limited in what it provides.

chrono
The most comphrehensive and full-featured datetime library, but more complex because of it.

Insertion-ordered map

indexmap
A HashMap that seperately keeps track of insertion order and allows you to efficiently iterate over its elements in that order

Stack-allocated arrays

arrayvec
Arrays that are ONLY stack-allocated with fixed capacity

smallvec
Arrays that are stack-allocated with fallback to the heap if the fixed stack capacity is exceeded

tinyvec
Stack allocated arrays in 100% safe Rust code but requires items to implement the Default trait.

HTTP Requests

reqwest
Full-fat HTTP client. Can be used in both synchronous and asynchronous code. Requires tokio runtime.

ureq
Minimal synchronous HTTP client focussed on simplicity and minimising dependencies.

Error Handling

Crates for more easily handling errors

Use Case Recommended Crates
For applications

anyhow
Provides a boxed error type that can hold any error, and helpers for generating an application-level stack trace.

For libraries

thiserror
Helps with generating boilerplate for enum-style error types.

Logging

Crates for logging. Note that in general you will need a seperate crate for actually printing/storing the logs

Use Case Recommended Crates
Text-based logging

tracing
Tracing is now the go-to crate for logging.

log
An older and simpler crate if your needs are simple and you are not using any async code.

Structured logging

tracing
Tracing is now the go-to crate for logging.

slog
Structured logging

Language Extensions

General purpose utility crates that extend language and/or stdlib functionality.

Use Case Recommended Crates
Lazy static variable initialization

once_cell
Newer crate with more ergonomic API. On track to be incorporated into the standard library. Should be preferred for all new projects.

lazy_static
Older crate. API is less convenient, but crate is stable and maintained.

Iterator helpers

itertools
A bunch of useful methods on iterators that aren't in the stdlib

Abstracting over different number types

num
Traits like Number, Add, etc that allow you write functions that are generic over the specific numeric type

Endian conversion

byteorder
Utility functions to convert between different endianness or read/write data with a specific endianness

Bitflags

bitflags
Strongly typed bitflag types

System

For low-level interaction with the underling platform / operating system

Use Case Recommended Crates
Memory mapping files

memmap2
The older memmap crate is unmaintained.

Libc

libc
Bindings for directly calling libc functions.

Windows (OS)

windows
The official Microsoft-provided crate for interacting with windows APIs

winapi
Older binding to the windows APIs. Unofficial, but more complete than windows-rs

Networking

TCP, HTTP, GRPc, etc. And the executors required to do asynchronous networking.

Async Executors

To do async programming using the async-await in Rust you need a runtime to execute drive your Futures.

Use Case Recommended Crates
General purpose

tokio
The oldest async runtime in the Rust ecosystem and still the most widely supported. Recommended for new projects.

async-std
A newer option that is very similar to tokio. Its API more closely mirrors the std library, but it doesn't have as much traction as Tokio.

io_uring

glommio
Use if you need io_uring support. Still somewhat experimental but rapidly maturing.

To do async programming using the async-await in Rust you need a runtime to execute drive your Futures.

Use Case Recommended Crates
Types & Interfaces

http
The `http` crate doesn't actually contain an HTTP implementation. Just types and interfaces to help interoperability.

Low-level HTTP Implementation

hyper
A low-level HTTP implementation (both client and server). Implements HTTP 1, 2, and 3. Requires the tokio async runtime.

TLS / SSL

rustls
A portable pure-rust implementation of TLS

rust-native-tls
Delegates to the system TLS implementations on windows and macOS, and uses OpenSSL on linux.

HTTP Client

reqwest
Full-fat HTTP client. Can be used in both synchronous and asynchronous code. Requires tokio runtime.

surf
Client that uses the async-std runtime rather than the tokio runtime.

ureq
Minimal synchronous HTTP client focussed on simplicity and minimising dependencies.

HTTP Server

axum
A minimal and ergonomic framework. An official part of the tokio project. Recommend for most new projects.

tide
Similar to Axum, but based on async-std rather than tokio

actix-web
A performance focussed framework. All Rust frameworks are fast, but choose actix-web if you need the absolutely maximum performance.

poem
Automatically generates OpenAPI defintions.

warp
Very similar to axum but with a quirkier API. This is a solid framework, but you should probably prefer Axum unless you particular like the API

rocket
Focussed on ergonomics. This is a solid framework, however development has stalled. Avoid for new projects.

Websockets

This section includes libraries for you to use just websockets. However note that many of the HTTP server frameworks in the section above also support websockets

Use Case Recommended Crates
Low-level

tungstenite-rs
Low-level crate that others build on

General Purpose

tokio-tungstenite
If you are using the tokio executor

async-tungstenite
If you are using the async-std executor

Use Case Recommended Crates
General Purpose

tonic
gRPC over HTTP/2 with full support for asynchronous code. Works with tokio



Argument Parsing

See argparse-benchmarks-rs for a full comparison of the crates mentioned here and more.

Use Case Recommended Crates
Fully-featured

clap
Ergonomic, supports everything, and is fast at runtime. However compile times can be slow

Minimal

lexopt
Fast compile times, fast runtime, pedantic about correctness. API is less ergonomic

pico-args
Fast compile times, fast runtime, more lax about correctness. API is more ergonomic

Utility

Helpers that are often useful when implementing CLIs

Use Case Recommended Crates
Globbing

globset
High-performance globbing that allows multiple globs to be evaluated at once

Directory walking

walkdir
Basic recursive filesystem walking.

ignore
Recursive filesystem walking that respects ignore files (like .gitignore)

File watching

watchexec
Watch files or directories and execute a function when they change

Terminal Rendering

For fancy terminal rendering and TUIs. The crates recommended here work cross-platform (including windows).

Use Case Recommended Crates
Coloured Output

termcolor
Cross-platform terminal colour output

Full TUI library

crossterm
Cross-platform terminal rendering and event handling

Concurrency

Data Structures

Use Case Recommended Crates
Mutex

parking_lot
std::mutex also works fine. But Parking Lot is faster.

Atomic pointer swapping

arc_swap
Useful for sharing data that has many readers but few writers

Concurrent HashMap

See conc-map-bench for comparative benchmarks of concurrent HashMaps.

dashmap
The fastest for general purpose workloads

flurry
Particularly good for read-heavy workloads.

Channels

See communicating-between-sync-and-async-code for notes on when to use async-specific channels vs general purpose channels.

crossbeam_channel
The absolute fastest channel implementation available. Implements Go-like 'select' feature.

flume
Smaller and simpler than crossbeam_channel and almost as fast

postage
Channels that integrate nicely with async code

Parallel computation

rayon
Convert sequential computation into parallel computation with one call - `par_iter` instead of `iter`


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK