Trait scratchpad::Marker
[−]
[src]
pub trait Marker { fn allocate<'marker, 't, T>(
&'marker self,
value: T
) -> Result<Allocation<'marker, 't, T>, Error> { ... } fn allocate_default<'marker, 't, T: Default>(
&'marker self
) -> Result<Allocation<'marker, 't, T>, Error> { ... } unsafe fn allocate_uninitialized<'marker, 't, T>(
&'marker self
) -> Result<Allocation<'marker, 't, T>, Error> { ... } fn allocate_array<'marker, 't, T: Clone>(
&'marker self,
len: usize,
value: T
) -> Result<Allocation<'marker, 't, [T]>, Error> { ... } fn allocate_array_default<'marker, 't, T: Default>(
&'marker self,
len: usize
) -> Result<Allocation<'marker, 't, [T]>, Error> { ... } fn allocate_array_with<'marker, 't, T, F: FnMut(usize) -> T>(
&'marker self,
len: usize,
func: F
) -> Result<Allocation<'marker, 't, [T]>, Error> { ... } unsafe fn allocate_array_uninitialized<'marker, 't, T>(
&'marker self,
len: usize
) -> Result<Allocation<'marker, 't, [T]>, Error> { ... } }
Scratchpad
allocation marker implementation trait.
This provides the shared interface for the MarkerFront
and
MarkerBack
types.
Provided Methods
fn allocate<'marker, 't, T>(
&'marker self,
value: T
) -> Result<Allocation<'marker, 't, T>, Error>
&'marker self,
value: T
) -> Result<Allocation<'marker, 't, T>, Error>
Allocates space for the given value, moving it into the allocation.
Examples
use scratchpad::Scratchpad; let scratchpad = Scratchpad::<[u64; 1], [usize; 1]>::new([0], [0]); let marker = scratchpad.mark_front().unwrap(); let x = marker.allocate(3.14159).unwrap(); assert_eq!(*x, 3.14159);
fn allocate_default<'marker, 't, T: Default>(
&'marker self
) -> Result<Allocation<'marker, 't, T>, Error>
&'marker self
) -> Result<Allocation<'marker, 't, T>, Error>
Allocates space for a value, initializing it to its default.
Examples
use scratchpad::Scratchpad; let scratchpad = Scratchpad::<[u64; 1], [usize; 1]>::new([0], [0]); let marker = scratchpad.mark_front().unwrap(); let x = marker.allocate_default::<f64>().unwrap(); assert_eq!(*x, 0.0);
unsafe fn allocate_uninitialized<'marker, 't, T>(
&'marker self
) -> Result<Allocation<'marker, 't, T>, Error>
&'marker self
) -> Result<Allocation<'marker, 't, T>, Error>
Allocates uninitialized space for the given type.
Safety
Since memory for the allocated data is uninitialized, it can
potentially be in an invalid state for a given type, leading to
undefined program behavior. It is recommended that one of the safe
allocate*()
methods are used instead if possible.
Examples
use scratchpad::Scratchpad; let scratchpad = Scratchpad::<[u64; 1], [usize; 1]>::new([0], [0]); let marker = scratchpad.mark_front().unwrap(); let mut x = unsafe { marker.allocate_uninitialized().unwrap() }; *x = 3.14159; assert_eq!(*x, 3.14159);
fn allocate_array<'marker, 't, T: Clone>(
&'marker self,
len: usize,
value: T
) -> Result<Allocation<'marker, 't, [T]>, Error>
&'marker self,
len: usize,
value: T
) -> Result<Allocation<'marker, 't, [T]>, Error>
Allocates space for an array, initializing each element with the given value.
Examples
use scratchpad::Scratchpad; let scratchpad = Scratchpad::<[u64; 3], [usize; 1]>::new([0; 3], [0]); let marker = scratchpad.mark_front().unwrap(); let x = marker.allocate_array(3, 3.14159).unwrap(); assert_eq!(*x, [3.14159, 3.14159, 3.14159]);
fn allocate_array_default<'marker, 't, T: Default>(
&'marker self,
len: usize
) -> Result<Allocation<'marker, 't, [T]>, Error>
&'marker self,
len: usize
) -> Result<Allocation<'marker, 't, [T]>, Error>
Allocates space for an array, initializing each element to its default value.
Examples
use scratchpad::Scratchpad; let scratchpad = Scratchpad::<[u64; 3], [usize; 1]>::new([0; 3], [0]); let marker = scratchpad.mark_front().unwrap(); let x = marker.allocate_array_default::<f64>(3).unwrap(); assert_eq!(*x, [0.0, 0.0, 0.0]);
fn allocate_array_with<'marker, 't, T, F: FnMut(usize) -> T>(
&'marker self,
len: usize,
func: F
) -> Result<Allocation<'marker, 't, [T]>, Error>
&'marker self,
len: usize,
func: F
) -> Result<Allocation<'marker, 't, [T]>, Error>
Allocates space for an array, initializing each element with the result of a function.
The function func
takes a single parameter containing the index of
the element being initialized.
Examples
use scratchpad::Scratchpad; let scratchpad = Scratchpad::<[u64; 3], [usize; 1]>::new([0; 3], [0]); let marker = scratchpad.mark_front().unwrap(); let x = marker.allocate_array_with(3, |index| index as f64).unwrap(); assert_eq!(*x, [0.0, 1.0, 2.0]);
unsafe fn allocate_array_uninitialized<'marker, 't, T>(
&'marker self,
len: usize
) -> Result<Allocation<'marker, 't, [T]>, Error>
&'marker self,
len: usize
) -> Result<Allocation<'marker, 't, [T]>, Error>
Allocates uninitialized space for an array of the given type.
Safety
Since memory for the allocated data is uninitialized, it can
potentially be in an invalid state for a given type, leading to
undefined program behavior. It is recommended that one of the safe
allocate*()
methods are used instead if possible.
Examples
use scratchpad::Scratchpad; let scratchpad = Scratchpad::<[u64; 3], [usize; 1]>::new([0; 3], [0]); let marker = scratchpad.mark_front().unwrap(); let mut x = unsafe { marker.allocate_array_uninitialized(3).unwrap() }; x[0] = 3.14159; x[1] = 4.14159; x[2] = 5.14159; assert_eq!(*x, [3.14159, 4.14159, 5.14159]);
Implementors
impl<'scratchpad, BufferT, TrackingT> Marker for MarkerFront<'scratchpad, BufferT, TrackingT> where
BufferT: 'scratchpad + Buffer,
TrackingT: 'scratchpad + Tracking,impl<'scratchpad, BufferT, TrackingT> Marker for MarkerBack<'scratchpad, BufferT, TrackingT> where
BufferT: 'scratchpad + Buffer,
TrackingT: 'scratchpad + Tracking,