Import num-derive-0.3.0 am: 75ab7e10d2 am: d5f837277a am: aa1165dc0d am: 4c9fffb298

Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/num-derive/+/1391410

Change-Id: Id962829964bcf37efc72bdc54de1df5b7d6d3943
tree: 3f574d32667e1823310c92cdacce52b4fa0cad6b
  1. src/
  2. tests/
  3. .cargo_vcs_info.json
  4. .gitignore
  5. Cargo.toml
  6. Cargo.toml.orig
  7. LICENSE-APACHE
  8. LICENSE-MIT
  9. README.md
  10. RELEASES.md
README.md

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.