[−][src]Struct heapnotize::Unit
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]
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
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,