numid

Crates.ionumid
lib.rsnumid
version0.2.9
sourcesrc
created_at2019-10-13 22:32:27.295274
updated_at2019-12-15 19:42:06.995774
descriptionA macro for generating structures which behave like numerical id.
homepage
repositoryhttps://github.com/powlpy/numid
max_upload_size
id172291
size35,795
(powlpy)

documentation

https://docs.rs/numid

README

numid

Build Status Crate Documentation Minimum rustc version License

This crate provide the numid! macro for generating structures which behave like numerical id.

Example

use numid::numid;

numid!(pub struct MyId -> 10);

fn main() {
    let id1 = MyId::new();
    let id2 = MyId::new();

    assert!(id2 > id1);
    assert_eq!(id1.value(), 11);
    assert_eq!(id2.value(), 12);
}

Usage

Add this to your Cargo.toml :

[dependencies]
numid = "0.2"

You can now create all the ids you want in your programs :

use numid::numid;

numid!(struct Id); // basic id
numid!(pub struct Id2); // public
numid!(pub(crate) struct Id3); // restricted public
numid!(#[doc(hidden)] struct Id4); // with attribut
numid!(struct Id5 -> 100); // init const specified
numid!(struct Id6(u128)); // type specified
numid!(@CloneIsReproduce struct Id7); // with in-macro special attribute
numid!(#[doc(hidden)] @CloneIsNew pub struct Id8(u32) -> 10); // all the thing you can want

Consult the documentation for more information.

TODO list

  • serde feature
Commit count: 51

cargo fmt