1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
//! A unique id generator for rust types. //! //! The crate provides a trait and a procedural macro. By deriving one, you implement the //! trait with `fn id() -> TypeId` static method which is unique in the whole project. //! Call API methods to interact with the service directly or user an iterator-like interface to //! //! For examples, see the `tests` directory in the source tree. //! //! # Usage //! //! ```rust //!#[macro_use] //!extern crate unique_type_id_derive; //!extern crate unique_type_id; //! //!fn sequential_id() { //! use unique_type_id::SequentialTypeId; //! //! #[derive(SequentialTypeId)] //! struct Test1; //! #[derive(SequentialTypeId)] //! struct Test2; //! //! assert_eq!(Test1::id().0, 0u64); //! assert_eq!(Test2::id().0, 1u64); //!} extern crate syn; extern crate quote; /// A strong type for type id. pub struct TypeId(pub u64); /// A trait for providing a sequential type id number. pub trait SequentialTypeId { /// Provides sequential type id number. fn id() -> TypeId; }