Space

Struct Space 

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

Specialized smart pointer to retrieve struct instances from a slice of memory.

The accessor methods of this struct all behave in a similar way: If the internal slice is big enough, they create a reference to the start of the slice with the desired type and create a new space object that contains the space after the references instance.

Implementations§

Source§

impl<'a> Space<'a>

Source

pub unsafe fn from_atom(atom: &LV2_Atom) -> Self

Create a new space from an atom pointer.

The method creates a space that contains the atom as well as it’s body.

§Safety

Since the body is not included in the atom reference, this method has to assume that it is valid memory and therefore is unsafe but sound.

Source

pub fn from_slice(data: &'a [u8]) -> Self

Create a new space from a slice.

Since everything regarding atoms is 64-bit-aligned, this method panics if the data slice is not 64-bit-aligned.

Source

pub fn split_raw(self, size: usize) -> Option<(&'a [u8], Self)>

Try to retrieve a slice of bytes.

This method basically splits off the lower part of the internal bytes slice and creates a new atom space pointer of the upper part. Since atoms have to be 64-bit-aligned, there might be a padding space that’s neither in the lower nor in the upper part.

Source

pub fn split_space(self, size: usize) -> Option<(Self, Self)>

Try to retrieve space.

This method calls split_raw and wraps the returned slice in an atom space. The second space is the space after the first one.

Source

pub fn split_type<T>(self) -> Option<(&'a T, Self)>
where T: Unpin + Copy + Send + Sync + Sized + 'static,

Try to retrieve a reference to a sized type.

This method retrieves a slice of memory using the split_raw method and interprets it as an instance of T. Since there is no way to check that the memory is actually a valid instance of T, this method is unsafe. The second return value is the space after the instance of T.

Source

pub fn split_atom(self) -> Option<(Self, Self)>

Try to retrieve the space occupied by an atom.

This method assumes that the space contains an atom and retrieves the space occupied by the atom, including the atom header. The second return value is the rest of the space behind the atom.

The difference to split_atom_body is that the returned space contains the header of the atom and that the type of the atom is not checked.

Source

pub fn split_atom_body<T: ?Sized>(self, urid: URID<T>) -> Option<(Self, Self)>

Try to retrieve the body of the atom.

This method retrieves the header of the atom. If the type URID in the header matches the given URID, it returns the body of the atom. If not, it returns None. The first space is the body of the atom, the second one is the space behind it.

The difference to split_atom is that the returned space does not contain the header of the atom and that the type of the atom is checked.

Source

pub fn from_reference<T: ?Sized>(instance: &'a T) -> Self

Create a space from a reference.

Source

pub fn concat(lhs: Self, rhs: Self) -> Option<Self>

Concatenate two spaces.

There are situations where a space is split too often and you might want to reunite these two adjacent spaces. This method checks if the given spaces are adjacent, which means that the left space has to end exactly where the right one begins. In this case, the concatenated space is returned. If this is not the case, this method returns None.

Source

pub fn data(&self) -> Option<&'a [u8]>

Return the internal slice of the space.

Source

pub fn mut_data(&mut self) -> &mut Option<&'a [u8]>

Return a mutable reference to the internal slice of the space.

Trait Implementations§

Source§

impl<'a> Clone for Space<'a>

Source§

fn clone(&self) -> Space<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Space<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Space<'a>

§

impl<'a> RefUnwindSafe for Space<'a>

§

impl<'a> Send for Space<'a>

§

impl<'a> Sync for Space<'a>

§

impl<'a> Unpin for Space<'a>

§

impl<'a> UnwindSafe for Space<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.