Struct ident::WithIdent[][src]

pub struct WithIdent<T, I = 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: DeriveIdent<I>, I> WithIdent<T, I>
[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.ident());

*wi = 10;
wi = WithIdent::update_ident(wi);
assert_eq!(10, *wi.ident());

impl<T, I> WithIdent<T, I>
[src]

Constructs a new WithIdent value from parts.

Params

identifier --- The unique identifier for value.
value --- The inner value of the WithIdent instance.

Returns an immutable reference to the identifier of this WithIdent.

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));

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));

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).ident());

impl<T, I: Eq> WithIdent<T, I>
[src]

Compares the identifiers of two WithIdent instances for equality.

impl<T, I: Clone> 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));

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: Eq, I> WithIdent<T, I>
[src]

Compares the values of two WithIdent instances for equality.

Trait Implementations

impl<T: DeriveIdent<I>, I> From<T> for WithIdent<T, I>
[src]

Performs the conversion.

impl<T: DeriveIdent<I> + Default, I> Default for WithIdent<T, I>
[src]

Returns the "default value" for a type. Read more

impl<T: PartialEq, I: PartialEq> PartialEq for WithIdent<T, I>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T: Eq, I: Eq> Eq for WithIdent<T, I>
[src]

impl<T: Clone, I: Clone> Clone for WithIdent<T, I>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: Copy, I: Copy> Copy for WithIdent<T, I>
[src]

impl<T: Debug, I: Debug> Debug for WithIdent<T, I>
[src]

Formats the value using the given formatter. Read more

impl<T, I> From<(I, T)> for WithIdent<T, I>
[src]

Performs the conversion.

impl<T, I> Into<(I, T)> for WithIdent<T, I>
[src]

Performs the conversion.

impl<T, I> Deref for WithIdent<T, I>
[src]

The resulting type after dereferencing.

Dereferences the value.

impl<T, I> DerefMut for WithIdent<T, I>
[src]

Mutably dereferences the value.

impl<T, I> Borrow<T> for WithIdent<T, I>
[src]

Immutably borrows from an owned value. Read more

impl<T, I> BorrowMut<T> for WithIdent<T, I>
[src]

Mutably borrows from an owned value. Read more

impl<T, I> AsRef<T> for WithIdent<T, I>
[src]

Performs the conversion.

impl<T, I> AsMut<T> for WithIdent<T, I>
[src]

Performs the conversion.

Auto Trait Implementations

impl<T, I> Send for WithIdent<T, I> where
    I: Send,
    T: Send

impl<T, I> Sync for WithIdent<T, I> where
    I: Sync,
    T: Sync