pub struct Nominal<T, M> { /* private fields */ }
Expand description
Nominal wrapper struct
This struct is zero cost; it is simply a type safe wrapper.
Newtypes are primarily created with assistance from the nominal
and
nominal_mod
macros. The macros will help save you the boilerplate of
writing the types and declaring unit structs to use as the marker.
Implementations§
Source§impl<T, M> Nominal<T, M>
impl<T, M> Nominal<T, M>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwraps the nominal struct and returns the value
Sourcepub fn as_value_ref(&self) -> &T
pub fn as_value_ref(&self) -> &T
Gets a reference to the wrapped value
Note: Deref
is not implemented on purpose, to prevent
unintentional auto-derefs
Sourcepub fn as_value_mut(&mut self) -> &mut T
pub fn as_value_mut(&mut self) -> &mut T
Gets a mut reference to the wrapped value
Note: DerefMut
is not implemented on purpose, to prevent
unintentional auto-derefs
Sourcepub fn with_other_marker<M2>(self) -> Nominal<T, M2>
pub fn with_other_marker<M2>(self) -> Nominal<T, M2>
Unwraps and rewraps the value as another nominal type, without modifying the wrapped value
If you’re using this function, make sure you know why you’re using it! after all, the whole point of this is to seperate otherwise identical types into newtypes based on semantic meaning.
Sourcepub fn map<T2, F>(self, f: F) -> Nominal<T2, M>where
F: FnOnce(T) -> T2,
pub fn map<T2, F>(self, f: F) -> Nominal<T2, M>where
F: FnOnce(T) -> T2,
Consumes and maps the wrapped value into another value, wrapping it in a nominal type with the same marker
Sourcepub async fn map_async<T2, F, Fu>(self, f: F) -> Nominal<T2, M>where
F: FnOnce(T) -> Fu,
Fu: IntoFuture<Output = T2>,
pub async fn map_async<T2, F, Fu>(self, f: F) -> Nominal<T2, M>where
F: FnOnce(T) -> Fu,
Fu: IntoFuture<Output = T2>,
Consumes and asyncronously maps the wrapped value into another value, wrapping it in a nominal type with the same marker
Source§impl<T, M, E> Nominal<Result<T, E>, M>
impl<T, M, E> Nominal<Result<T, E>, M>
Trait Implementations§
Source§impl<T, M, TR, MR> PartialOrd<Nominal<TR, MR>> for Nominal<T, M>where
T: PartialOrd<TR>,
impl<T, M, TR, MR> PartialOrd<Nominal<TR, MR>> for Nominal<T, M>where
T: PartialOrd<TR>,
impl<T, M> Copy for Nominal<T, M>where
T: Copy,
impl<T, M> Eq for Nominal<T, M>where
T: Eq,
Auto Trait Implementations§
impl<T, M> Freeze for Nominal<T, M>where
T: Freeze,
impl<T, M> RefUnwindSafe for Nominal<T, M>where
T: RefUnwindSafe,
M: RefUnwindSafe,
impl<T, M> Send for Nominal<T, M>
impl<T, M> Sync for Nominal<T, M>
impl<T, M> Unpin for Nominal<T, M>
impl<T, M> UnwindSafe for Nominal<T, M>where
T: UnwindSafe,
M: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.