Struct SpaceHead

Source
pub struct SpaceHead<'a> { /* private fields */ }
Expand description

A mutable space that dynamically allocates memory.

This space uses a linked list of SpaceElements to allocate memory. Every time allocate is called, a new element is appended to the list and a new byte slice is created.

In order to use this space and retrieve the written data once it was written, you create a SpaceElement and create a new head with it. Then, you use the head like any other MutSpace and when you’re done, you retrieve the written data by either calling to_vec or iter.

§Usage example

// URID cache creation is omitted.
let urids: AtomURIDCollection = map.populate_collection().unwrap();

// Creating the first element in the list and the writing head.
let mut element = SpaceElement::default();
let mut head = SpaceHead::new(&mut element);

// Writing an integer.
(&mut head as &mut dyn MutSpace).init(urids.int, 42).unwrap();

// Retrieving a continuos vector with the written data and verifying it's contents.
let written_data: Vec<u8> = element.to_vec();
let atom = UnidentifiedAtom::new(Space::from_slice(written_data.as_ref()));
assert_eq!(42, atom.read(urids.int, ()).unwrap());

Implementations§

Source§

impl<'a> SpaceHead<'a>

Source

pub fn new(element: &'a mut SpaceElement) -> Self

Create a new head that references the given element.

Trait Implementations§

Source§

impl<'a> MutSpace<'a> for SpaceHead<'a>

Source§

fn allocate( &mut self, size: usize, apply_padding: bool, ) -> Option<(usize, &'a mut [u8])>

Try to allocate memory on the internal data slice. Read more
Source§

fn write_raw( &mut self, data: &[u8], apply_padding: bool, ) -> Option<&'a mut [u8]>

Try to write data to the internal data slice. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SpaceHead<'a>

§

impl<'a> RefUnwindSafe for SpaceHead<'a>

§

impl<'a> Send for SpaceHead<'a>

§

impl<'a> Sync for SpaceHead<'a>

§

impl<'a> Unpin for SpaceHead<'a>

§

impl<'a> !UnwindSafe for SpaceHead<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.