#mathematics #numerics

macro num-derive

Numeric syntax extensions

16 releases

✓ Uses Rust 2018 edition

0.3.0 Sep 27, 2019
0.2.5 Apr 23, 2019
0.2.4 Jan 26, 2019
0.2.3 Oct 3, 2018
0.1.38 Nov 28, 2016

#9 in Math

Download history 21663/week @ 2019-08-16 25065/week @ 2019-08-23 22766/week @ 2019-08-30 24541/week @ 2019-09-06 22894/week @ 2019-09-13 24564/week @ 2019-09-20 26021/week @ 2019-09-27 28261/week @ 2019-10-04 26631/week @ 2019-10-11 26459/week @ 2019-10-18 26656/week @ 2019-10-25 28368/week @ 2019-11-01 28711/week @ 2019-11-08 27796/week @ 2019-11-15 26635/week @ 2019-11-22

94,484 downloads per month
Used in 612 crates (99 directly)

MIT/Apache

31KB
561 lines

num-derive

crate documentation minimum rustc 1.31 Travis status

Procedural macros to derive numeric traits in Rust.

Usage

Add this to your Cargo.toml:

[dependencies]
num-traits = "0.2"
num-derive = "0.3"

and this to your crate root:

#[macro_use]
extern crate num_derive;

Then you can derive traits on your own types:

#[derive(FromPrimitive, ToPrimitive)]
enum Color {
    Red,
    Blue,
    Green,
}

Optional features

  • full-syntax — Enables num-derive to handle enum discriminants represented by complex expressions. Usually can be avoided by utilizing constants, so only use this feature if namespace pollution is undesired and compile time doubling is acceptable.

Releases

Release notes are available in RELEASES.md.

Compatibility

The num-derive crate is tested for rustc 1.31 and greater.

Dependencies

~0.5–0.8MB
~20K SLoC