pub( crate ) mod private
{
use crate::protected::*;
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( 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
{
}
impl fmt::Debug for Id
{
fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result
{
f.write_fmt( format_args!( "id::{:?}", self.in_id ) )
}
}
}
crate::mod_interface!
{
exposed use Id;
prelude use { IdInterface, HasIdInterface };
}