pub struct SpaceHead<'a> { /* private fields */ }
Expand description
A mutable space that dynamically allocates memory.
This space uses a linked list of SpaceElement
s 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§
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more