pub( crate ) mod private
{
use crate::*;
use once_cell::sync::Lazy;
use std::sync::Mutex;
use core::hash::Hash;
static mut COUNTER : Lazy< Mutex< i64 > > = Lazy::new( ||
{
Mutex::new( 0 )
});
pub trait IdInterface
where
Self :
fmt::Debug +
Clone +
Copy +
PartialEq +
Eq +
Hash +
,
{
}
pub trait HasIdInterface
where
Self :
fmt::Debug +
{
fn id( &self ) -> Id;
}
#[ derive( Debug, Clone, Copy, PartialEq, Eq, Hash ) ]
pub struct Id
{
#[ allow( dead_code ) ]
in_id : i64,
}
impl Id
{
pub fn new< T >() -> Self
where
T : core::any::Any,
{
let mut c = unsafe { COUNTER.lock().unwrap() };
*c += 1;
Self
{
in_id : *c,
}
}
}
impl IdInterface for Id
{
}
}
pub mod protected
{
pub use super::
{
orphan::*,
};
}
pub use protected::*;
pub mod orphan
{
pub use super::exposed::*;
}
pub mod exposed
{
pub use super::
{
prelude::*,
private::Id,
};
}
pub use exposed::*;
pub mod prelude
{
pub use super::private::
{
IdInterface,
HasIdInterface,
};
}