scsys_core/id/
mod.rs

1/*
2    Appellation: ids <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5//! This module focuses on the [`Id`] implementation, a generic wrapper type used to define
6//! various identifiers. The `Id` type is equipped with additional methods and traits to
7//! facilitate the creation and management of identifiers in a type-safe manner.
8#[doc(inline)]
9pub use self::{identifier::Id, traits::*, types::*};
10
11mod identifier;
12
13mod impls {
14    pub mod impl_id;
15    pub mod impl_id_ops;
16    pub mod impl_id_repr;
17
18    #[allow(deprecated)]
19    mod impl_id_deprecated;
20    #[cfg(feature = "rand")]
21    pub mod impl_id_rand;
22}
23
24mod traits {
25    //! this module implements various traits supporting the [`Id`](super::Id) type
26    #[doc(inline)]
27    pub use self::prelude::*;
28
29    mod id;
30    mod identifier;
31
32    mod prelude {
33        #[doc(inline)]
34        pub use super::id::*;
35        #[doc(inline)]
36        pub use super::identifier::*;
37    }
38}
39
40mod types {
41    #[doc(inline)]
42    pub use self::prelude::*;
43
44    mod multi_id;
45
46    mod prelude {
47        #[doc(inline)]
48        pub use super::multi_id::IndexId;
49    }
50}
51
52pub(crate) mod prelude {
53    #[doc(inline)]
54    pub use super::identifier::Id;
55    #[doc(inline)]
56    pub use super::traits::*;
57    #[doc(inline)]
58    pub use super::types::*;
59}
60
61#[cfg(test)]
62mod tests {
63    use super::Id;
64
65    #[test]
66    fn test_id() {
67        let mut id = Id::<usize>::default();
68        assert_eq!(id.get(), &0);
69        assert_eq!(id.get_mut(), &mut 0);
70        let view = id.view();
71        assert_eq!(view.get(), &&0);
72        assert_eq!(view.copied(), id);
73    }
74
75    #[test]
76    fn test_atomic_id() {
77        let v1 = Id::atomic();
78        let v2 = Id::atomic();
79        assert_ne!(v1, v2);
80    }
81
82    #[test]
83    fn test_id_stepper() {
84        let mut id: Id<usize> = Id::zero();
85        assert_eq!(id.step(), 0);
86        assert_eq!(id.step(), 1);
87        assert_eq!(id.step(), 2);
88        assert_eq!(id.step(), 3);
89        assert_eq!(id.step(), 4);
90        assert_eq!(id, 5);
91    }
92}