[][src]Struct heapnotize::Unit

pub struct Unit<'a, T> { /* fields omitted */ }

A type serving as an owner of a value stored on the Rack.

A Unit can be obtained by adding a value to the Rack. After that, it can be used to access the value, both mutably and immutably. Once the Unit gets out of the scope, the value that it holds gets dropped.

Implementations

impl<T, '_> Unit<'_, T>[src]

pub fn get_ref(&self) -> &T[src]

Get a reference to the data stored on the Rack.

Examples

Reference to the stored value can be accessed using this method:

let rack = Rack64::new();
let five = rack.must_add(5);
assert_eq!(*five.get_ref(), 5);

The stored value can be also accessed using a dereference *:

let rack = Rack64::new();
let five = rack.must_add(5);
assert_eq!(*five, 5);

Finally, this allows users to use defer coercion and pass &Unit<T> to functions accepting &T:

fn add_one(num: &i32) -> i32 {
    num + 1
}

let rack = Rack64::new();
let five = rack.must_add(5);

assert_eq!(add_one(&five), 6)

pub fn get_mut(&mut self) -> &mut T[src]

Get a mutable reference to the data stored on the Rack.

Examples

Mutable reference to the stored value can be obtained using this method:

let rack = Rack64::new();

let mut number = rack.must_add(5);
*number.get_mut() = 10;

assert_eq!(*number.get_ref(), 10);

The stored value can be also changed directly using a dereference *:

let rack = Rack64::new();

let mut number = rack.must_add(5);
*number = 10;

assert_eq!(*number, 10);

Finally, this allows users to use defer coercion and pass &mut Unit<T> to functions accepting &mut T:

fn set_to_ten(num: &mut i32) {
    *num = 10;
}

let rack = Rack64::new();

let mut number = rack.must_add(5);
set_to_ten(&mut number);

assert_eq!(*number, 10)

Trait Implementations

impl<'a, T: Debug> Debug for Unit<'a, T>[src]

impl<T, '_> Deref for Unit<'_, T>[src]

type Target = T

The resulting type after dereferencing.

impl<T, '_> DerefMut for Unit<'_, T>[src]

impl<T, '_> Drop for Unit<'_, T>[src]

When the Unit gets out of scope, it will deallocate its space on the Rack and make sure that the stored value gets properly dropped.

Auto Trait Implementations

impl<'a, T> !Send for Unit<'a, T>

impl<'a, T> !Sync for Unit<'a, T>

impl<'a, T> Unpin for Unit<'a, T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.