Struct scratchpad::Allocation [] [src]

pub struct Allocation<'marker, 't, T: ?Sized> where
    T: 't, 
{ /* fields omitted */ }

Scratchpad Marker allocation.

Markers implement the Deref and DerefMut traits, allowing the data to be dereferenced explicitly using the unary * operator (e.g. *allocation) or implicitly by the compiler under various circumstances.

An allocation is statically bound to the lifetime of the Marker from which it is allocated, ensuring that no dangling references can be left when the Marker is dropped.

Methods

impl<'marker, 't, T> Allocation<'marker, 't, T> where
    T: 't + Sized
[src]

[src]

Moves the value out of the Allocation.

Note that this is only implemented for Sized value types.

Examples

use scratchpad::Scratchpad;

let x = {
    let scratchpad = Scratchpad::<[u64; 1], [usize; 1]>::new(
        [0],
        [0],
    );
    let marker = scratchpad.mark_front().unwrap();
    let allocation = marker.allocate(3.14159).unwrap();

    allocation.unwrap()
};

// Value was moved out of the allocation, so it can now outlive the
// scratchpad in which it was initially created.
assert_eq!(x, 3.14159);

Trait Implementations

impl<'marker, 't, T: ?Sized> Deref for Allocation<'marker, 't, T> where
    T: 't, 
[src]

The resulting type after dereferencing.

[src]

Dereferences the value.

impl<'marker, 't, T: ?Sized> DerefMut for Allocation<'marker, 't, T> where
    T: 't, 
[src]

[src]

Mutably dereferences the value.

impl<'marker, 't, T: ?Sized> Drop for Allocation<'marker, 't, T> where
    T: 't, 
[src]

[src]

Executes the destructor for this type. Read more

impl<'marker, 't, T: ?Sized> Debug for Allocation<'marker, 't, T> where
    T: 't + Debug
[src]

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<'marker, 't, T: ?Sized> Send for Allocation<'marker, 't, T> where
    T: Send

impl<'marker, 't, T: ?Sized> Sync for Allocation<'marker, 't, T> where
    T: Sync