[][src]Struct lv2::prelude::Space

pub struct Space<'a> { /* fields omitted */ }

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

impl<'a> Space<'a>[src]

pub unsafe fn from_atom(atom: &LV2_Atom) -> Space<'a>[src]

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.

pub fn from_slice(data: &'a [u8]) -> Space<'a>[src]

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.

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

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.

pub fn split_space(self, size: usize) -> Option<(Space<'a>, Space<'a>)>[src]

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.

pub fn split_type<T>(self) -> Option<(&'a T, Space<'a>)> where
    T: Unpin + Copy + Send + Sync + 'static, 
[src]

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.

pub fn split_atom(self) -> Option<(Space<'a>, Space<'a>)>[src]

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.

pub fn split_atom_body<T>(self, urid: URID<T>) -> Option<(Space<'a>, Space<'a>)> where
    T: ?Sized
[src]

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.

pub fn from_reference<T>(instance: &'a T) -> Space<'a> where
    T: ?Sized
[src]

Create a space from a reference.

pub fn concat(lhs: Space<'a>, rhs: Space<'a>) -> Option<Space<'a>>[src]

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.

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

Return the internal slice of the space.

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

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

Trait Implementations

impl<'a> Clone for Space<'a>[src]

impl<'a> Copy for Space<'a>[src]

Auto Trait Implementations

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.