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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#![cfg_attr(not(doctest), doc = include_str!("../README.md") )]

#![feature(once_cell)]
#![warn(missing_docs)]

#![deny(rustdoc::broken_intra_doc_links)]

#![warn(clippy::pedantic)]
#![allow(clippy::must_use_candidate)]

/// Definition of the [`Id`] struct.
pub mod identity;
/// Definition of the [`Scope`] trait.
pub mod scope;

pub use identity::{GlobalId, Id, IdHandle};
pub use scope::{GlobalScope, Scope};

#[cfg(feature = "derive")]
#[doc(hidden)]
pub use dmv_derive::*;

/// Creates a new [`Id`] with scope `S`.
#[must_use]
pub fn register<S: Scope>() -> Id<S> {
    Id::new()
}

/// Creates a new [`Id`] with scope [`GlobalScope`].
///
/// This function is equivalent to [`register::<GlobalScope>()`].
#[must_use]
pub fn register_global() -> Id<GlobalScope> {
    register()
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::scope::GlobalScope;

    #[test]
    fn test_basic() {
        let id1 = register::<GlobalScope>();
        let id2 = register::<GlobalScope>();
        assert_ne!(id1, id2);
    }

    #[test]
    fn test_global() {
        let id1 = register_global();
        let id2 = register_global();
        assert_ne!(id1, id2);
    }
}