mod private
{
use crate::prelude::*;
use core::fmt;
use core::hash::Hash;
use core::cmp::{ PartialEq, Eq };
#[ allow( unused_imports ) ]
use crate::dt::prelude::*;
#[ derive( Debug, PartialEq, Eq, Copy, Clone, Hash, Default ) ]
pub struct IdentityWithPointer( usize );
impl IdentityWithPointer
{
#[ inline ]
pub fn make< T >( src : &T ) -> Self
{
let ptr = unsafe
{
core::mem::transmute::< _, usize >( src )
};
Self( ptr )
}
}
impl< 'a, T > From< &'a T > for IdentityWithPointer
{
fn from( src : &'a T ) -> Self
{
let ptr = unsafe
{
core::mem::transmute::< _, usize >( src )
};
Self( ptr )
}
}
#[ derive( PartialEq, Eq, Copy, Clone, Hash ) ]
pub struct IdentityWithName( pub &'static str )
;
impl IdentityWithName
{
#[ inline ]
pub fn make( val : &'static str ) -> Self
{
Self( val )
}
}
impl From< &'static str > for IdentityWithName
{
fn from( src : &'static str ) -> Self
{
Self( src )
}
}
impl< Src > From< &Src > for IdentityWithName
where
Src : Clone,
IdentityWithName : From< Src >,
{
fn from( src : &Src ) -> Self
{
From::< Src >::from( src.clone() )
}
}
impl fmt::Debug for IdentityWithName
{
fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result
{
f.write_fmt( format_args!( "{}", self.0 ) )
}
}
#[ derive( PartialEq, Eq, Copy, Clone, Hash, derive_tools::From, derive_tools::Deref ) ]
pub struct IdentityWithInt( isize );
#[ derive( Debug, Copy, Clone, Default ) ]
pub struct IdGeneratorInt
{
counter : IdentityWithInt,
}
impl IdGeneratorTrait< IdentityWithInt > for IdGeneratorInt
{
fn id_next( &mut self ) -> IdentityWithInt
{
self.counter.0 += 1;
self.counter
}
fn is_id_valid( &self, src : IdentityWithInt ) -> bool
{
src.0 >= 0 && src.0 < self.counter.0
}
}
impl HasIdGenerator< IdentityWithInt > for IdentityWithInt
{
type Generator = IdGeneratorInt;
}
impl Default for IdentityWithInt
{
fn default() -> Self { Self( 1 ) }
}
impl fmt::Debug for IdentityWithInt
{
fn fmt( &self, f : &mut fmt::Formatter<'_> ) -> fmt::Result
{
f.write_fmt( format_args!( "{}", self.0 ) )
}
}
}
crate::mod_interface!
{
exposed use super::private::
{
IdentityWithPointer,
IdentityWithName,
IdentityWithInt,
IdGeneratorInt,
};
}