Macro enso_shapely::newtype_prim [−][src]
macro_rules! newtype_prim { ($( $(#$meta:tt)* $name:ident($type:ty); )*) => { ... }; }
Expand description
Generates a newtype wrapper for the provided types. It also generates a lot of impls, including Copy, Clone, Debug, Default, Display, From, Into, Deref, and DerefMut.
For the following input:
ⓘ
newtype_prim! { AttributeIndex(usize); }
The following code is generated:
ⓘ
#[derive(Copy,Clone,CloneRef,Debug,Default,Display,Eq,Hash,Ord,PartialOrd,PartialEq)] pub struct AttributeIndex { raw: usize } impl AttributeIndex { /// Constructor. pub fn new(raw:usize) -> Self { Self { raw } } } impl Deref for AttributeIndex { type Target = usize; fn deref(&self) -> &Self::Target { &self.raw } } impl DerefMut for AttributeIndex { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.raw } } impl From<usize> for AttributeIndex { fn from(t:usize) -> Self { Self::new(t) } } impl From<&usize> for AttributeIndex { fn from(t:&usize) -> Self { Self::new(*t) } } impl From<&&usize> for AttributeIndex { fn from(t:&&usize) -> Self { Self::new(**t) } } impl From<AttributeIndex> for usize { fn from(t:AttributeIndex) -> Self { t.raw } } impl From<&AttributeIndex> for usize { fn from(t:&AttributeIndex) -> Self { t.raw } } impl From<&&AttributeIndex> for usize { fn from(t:&&AttributeIndex) -> Self { t.raw } }