Struct ident::WithIdent
[−]
[src]
pub struct WithIdent<T, I: Eq = usize> { /* fields omitted */ }
WithIdent
wraps any value of type T
and a unique identifier of type I
.
The fields of a WithIdent
instance cannot be accessed but the T
value can be
accessed via a Box
like interface.
It can be useful to think of WithIdent
as a tuple of (I, T)
, so From
and Into
have been implemented for just that conversion.
Methods
impl<T, I: Eq> WithIdent<T, I>
[src]
pub fn new(identifier: I, value: T) -> Self
[src]
Constructs a new WithIdent
value from parts.
Params
identifier --- The unique identifier
for value
.
value --- The inner value
of the WithIdent
instance.
pub fn get_identifier(&self) -> &I
[src]
Returns an immutable reference to the identifier
of this WithIdent
.
pub fn same_ident<U>(a: &WithIdent<T, I>, b: &WithIdent<U, I>) -> bool
[src]
Compares the identifiers
of two WithIdent
instances for equality.
pub fn into_value(wi: Self) -> T
[src]
Consumes the WithIdent
returning the wrapped T
value.
Note: this is an associated function, which means that you have to call it as
WithIdent::into_value(wi)
instead of wi.into_value()
. This is so that there is no
conflict with a method on the inner type.
Examples
let wi = WithIdent::new(0, 5); assert_eq!(5, WithIdent::into_value(wi));
pub fn map<F, U>(wi: Self, f: F) -> WithIdent<U, I> where
F: FnOnce(T) -> U,
[src]
F: FnOnce(T) -> U,
Consumes the WithIdent
returning a new instance wrapping the result of the mapping.
Note: this is an associated function, which means that you have to call it as
WithIdent::map(wi, f)
instead of wi.map(f)
. This is so that there is no conflict
with a method on the inner type.
Note: the returned WithIdent
will still have the same identifier
as the consumed instance.
Examples
let wi = WithIdent::new(0, 5); assert_eq!(10, *WithIdent::map(wi, |x| 2 * x));
pub fn map_ident<F, U>(wi: Self, f: F) -> WithIdent<T, U> where
F: FnOnce(I) -> U,
U: Eq,
[src]
F: FnOnce(I) -> U,
U: Eq,
Consumes the WithIdent
returning a new instance with an updated identifier
.
Note: this is an associated function, which means that you have to call it as
WithIdent::map_ident(wi, f)
instead of wi.map_ident(f)
. This is so that there is no conflict
with a method on the inner type.
Note: the returned WithIdent
will still have the same inner value as the consumed instance.
Examples
let wi = WithIdent::new(0, 5); assert_eq!(1, *WithIdent::map_ident(wi, |x| x + 1).get_identifier());
impl<T, I: Eq + Clone> WithIdent<T, I>
[src]
pub fn as_ref(wi: &Self) -> WithIdent<&T, I>
[src]
Returns a new WithIdent
instance wrapping a reference to the original value.
Note: this is an associated function, which means that you have to call it as
WithIdent::as_ref(&wi)
instead of wi.as_ref()
. This is so that there is no conflict
with a method on the inner type.
Examples
let wi = WithIdent::new(0, 5); assert_eq!(&5, *WithIdent::as_ref(&wi));
pub fn as_mut(wi: &mut Self) -> WithIdent<&mut T, I>
[src]
Returns a new WithIdent
instance wrapping a mutable reference to the original value.
Note: this is an associated function, which means that you have to call it as
WithIdent::as_mut(&mut wi)
instead of wi.as_mut()
. This is so that there is
no conflict with a method on the inner type.
Examples
let mut wi = WithIdent::new(0, 5); assert_eq!(5, **WithIdent::as_mut(&mut wi));
impl<T: DeriveIdent<I>, I: Eq> WithIdent<T, I>
[src]
pub fn update_ident(wi: Self) -> Self
[src]
Consumes the WithIdent
and returns a new instance with an updated identifier
derived from the inner value.
Note: this is an associated function, which means that you have to call it as
WithIdent::update_ident(wi)
instead of wi.update_ident()
. This is so that
there is no conflict with a method on the inner type.
Examples
let mut wi = WithIdent::from(5); assert_eq!(5, *wi.get_identifier()); *wi = 10; wi = WithIdent::update_ident(wi); assert_eq!(10, *wi.get_identifier());
impl<T: Eq, I: Eq> WithIdent<T, I>
[src]
pub fn same_value<U: Eq>(a: &WithIdent<T, I>, b: &WithIdent<T, U>) -> bool
[src]
Compares the values
of two WithIdent
instances for equality.
Trait Implementations
impl<T: DeriveIdent<I>, I: Eq> From<T> for WithIdent<T, I>
[src]
impl<T: PartialEq, I: PartialEq + Eq> PartialEq for WithIdent<T, I>
[src]
fn eq(&self, __arg_0: &WithIdent<T, I>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &WithIdent<T, I>) -> bool
[src]
This method tests for !=
.
impl<T: Eq, I: Eq + Eq> Eq for WithIdent<T, I>
[src]
impl<T: Clone, I: Clone + Eq> Clone for WithIdent<T, I>
[src]
fn clone(&self) -> WithIdent<T, I>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: Copy, I: Copy + Eq> Copy for WithIdent<T, I>
[src]
impl<T: Debug, I: Debug + Eq> Debug for WithIdent<T, I>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<T, I: Eq> From<(I, T)> for WithIdent<T, I>
[src]
impl<T, I: Eq> Into<(I, T)> for WithIdent<T, I>
[src]
impl<T, I: Eq> Deref for WithIdent<T, I>
[src]
type Target = T
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
Dereferences the value.
impl<T, I: Eq> DerefMut for WithIdent<T, I>
[src]
impl<T, I: Eq> Borrow<T> for WithIdent<T, I>
[src]
impl<T, I: Eq> BorrowMut<T> for WithIdent<T, I>
[src]
fn borrow_mut(&mut self) -> &mut T
[src]
Mutably borrows from an owned value. Read more