1. rayon


2. std::borrow::Cow

pub enum Cow<'a, B> 
    B: 'a + ToOwned + ?Sized, 
    Borrowed(&'a B),

A clone-on-write smart pointer.
The type Cow is a smart pointer providing clone-on-write functionality: it can enclose and provide immutable access to borrowed data, and clone the data lazily when mutation or ownership is required. The type is designed to work with general borrowed data via the Borrow trait.
Cow implements Deref, which means that you can call non-mutating methods directly on the data it encloses. If mutation is desired, to_mut will obtain a mutable reference to an owned value, cloning if necessary.

use std::borrow::Cow;

fn abs_all(input: &mut Cow<[i32]>) {
    for i in 0..input.len() {
        let v = input[i];
        if v < 0 {
            // Clones into a vector if not already owned.
            input.to_mut()[i] = -v;

// No clone occurs because `input` doesn't need to be mutated.
let slice = [0, 1, 2];
let mut input = Cow::from(&slice[..]);
abs_all(&mut input);

// Clone occurs because `input` needs to be mutated.
let slice = [-1, 0, 1];
let mut input = Cow::from(&slice[..]);
abs_all(&mut input);

// No clone occurs because `input` is already owned.
let mut input = Cow::from(vec![-1, 0, 1]);
abs_all(&mut input);

3. Derivative

This crate provides a set of alternative #[derive] attributes for Rust.
derivative uses attributes to make it possible to derive more implementations than the built-in derive(Trait). Here are a few examples of stuffs you cannot just derive.

4. gmp_mpfr_sys

gmp_mpfr_sys为Rust底层FFI(外部函数接口Foreign Function Interface)库,提供与GNU任意精度库的连接:

  • FFI接口 for GMP:整数和有理数;
  • FFI接口 for MPFR:浮点数
  • FFI接口 for MPC:复数。


5. cargo watch

cargo-watch自动化构建工具通过运行cargo watch命令,可监测所在代码工程里的变化,并运行相应的命令。监控修改并自动运行相应的命令,不用手工编译运行。

cargo install cargo-watch
# Run tests only
$ cargo watch -x test

# Run check then tests
$ cargo watch -x check -x test

# Run run with arguments
$ cargo watch -x 'run -- --some-arg'

# Run an arbitrary command
$ cargo watch -s 'echo Hello world'

6. cargo edit

cargo-edit通过运行cargo add/rm/upgrade等命令来对Cargo.toml中的依赖项进行管理。

cargo install cargo-edit
$ # Add a specific version
$ cargo add regex@0.1.41 --dev
$ # Query the latest version from and adds it as build dependency
$ cargo add gcc --build
$ # Add a crate
$ cargo add local_experiment --path=lib/trial-and-error/
$ # Add a crate; the crate name will be found automatically
$ cargo add lib/trial-and-error/
$ # Add a crate with a local development path
$ cargo add my_helper --vers=1.3.1 --path=lib/my-helper/
$ # Add a renamed dependency
$ cargo add thiserror --rename error

7. borsh

Borsh stands for Binary Object Representation Serializer for Hashing. It is meant to be used in security-critical projects as it prioritizes consistency, safety, speed, and comes with a strict specification.

use borsh::{BorshSerialize, BorshDeserialize};

#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)]
struct A {
    x: u64,
    y: String,

fn test_simple_struct() {
    let a = A {
        x: 3301,
        y: "liber primus".to_string(),
    let encoded_a = a.try_to_vec().unwrap();
    let decoded_a = A::try_from_slice(&encoded_a).unwrap();
    assert_eq!(a, decoded_a);