[−][src]Trait lv2rs_atom::AtomBody
Abstraction of atom bodies.
Atom bodies can be very different in size and shape and therefore, this trait contains only a small set of things atoms are capable of.
Implementing your own atom bodies.
First of all, you shouldn't. The set of included atom bodies is enough to express almost any
information. On the other hand, if you really need to implement a new atom body, just implement
this trait. This will give you most of the features you will need. However, this trait only
lets you initialize a body; It does not give you means to extend it afterwards. If you want to
do that, you should create an extension trait for WritingFrame
s,
just like the TupleWritingFrame
.
Associated Types
type InitializationParameter: ?Sized
The type of the parameter for initialize_body
Since Rust does not support generic associated types yet, you can not use references here.
However, since initialize_body
will receive a reference of this type, you can place
unsized types in here, like slices.
Required methods
fn get_uri() -> &'static CStr
Return the URI of the atom type.
unsafe fn initialize_body<'a, W>(
writer: &mut W,
parameter: &Self::InitializationParameter,
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
writer: &mut W,
parameter: &Self::InitializationParameter,
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
Write out a basic but valid atom body.
Implementors should use the writing frame to write out general information about the atom, like body-specific headers or, in the case of scalars, the value itself. Please note that
- The
Atom
was already written, you do not need to write it yourself. - You cannot alter the data after it was written. Once this method call is over, you only have
reading access to it by using the
get_atom_body
method of the writing frame. - The result must be a valid atom. You may not rely on future calls to make it valid.
- In most cases, you don't need to include padding. If padding is required, the writer will include it when it is dropped.
- You do not need (and definitely should not try) to update the atom header for the new size. The writer will keep track of that.
- Your implementation should work in a way that it can only return
Err
in cases of insufficient memory.
This method is unsafe since it can tamper if the integrity of the atom structure, for example if called twice.
fn create_ref<'a>(raw_body: &'a [u8]) -> Result<&'a Self, ()>
Try to create a Self
reference from a slice of raw data.
When implementing, you have to check if the data makes up a valid object of your type. If
this is not the case, return an Err
.
Implementors
impl AtomBody for Literal
[src]
type InitializationParameter = URID
fn get_uri() -> &'static CStr
[src]
unsafe fn initialize_body<'a, W>(
writer: &mut W,
language: &URID,
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
[src]
writer: &mut W,
language: &URID,
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
fn create_ref<'a>(raw_data: &'a [u8]) -> Result<&'a Self, ()>
[src]
impl AtomBody for Object
[src]
type InitializationParameter = (URID, URID)
fn get_uri() -> &'static CStr
[src]
unsafe fn initialize_body<'a, W>(
writer: &mut W,
(id, otype): &(URID, URID),
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
[src]
writer: &mut W,
(id, otype): &(URID, URID),
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
fn create_ref<'a>(raw_body: &'a [u8]) -> Result<&'a Self, ()>
[src]
impl AtomBody for Sequence
[src]
type InitializationParameter = TimeUnit
fn get_uri() -> &'static CStr
[src]
unsafe fn initialize_body<'a, W>(
writer: &mut W,
parameter: &TimeUnit,
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
[src]
writer: &mut W,
parameter: &TimeUnit,
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
fn create_ref<'a>(raw_data: &'a [u8]) -> Result<&'a Self, ()>
[src]
impl AtomBody for AtomString
[src]
type InitializationParameter = CStr
fn get_uri() -> &'static CStr
[src]
unsafe fn initialize_body<'a, W>(
writer: &mut W,
string: &CStr,
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
[src]
writer: &mut W,
string: &CStr,
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
fn create_ref<'a>(raw_data: &'a [u8]) -> Result<&'a Self, ()>
[src]
impl AtomBody for Tuple
[src]
type InitializationParameter = ()
fn get_uri() -> &'static CStr
[src]
unsafe fn initialize_body<'a, W>(
writer: &mut W,
parameter: &(),
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
[src]
writer: &mut W,
parameter: &(),
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
fn create_ref<'a>(raw_data: &'a [u8]) -> Result<&'a Self, ()>
[src]
impl<T> AtomBody for Vector<T> where
T: 'static + AtomBody + Sized + Copy,
[src]
T: 'static + AtomBody + Sized + Copy,
type InitializationParameter = ()
fn get_uri() -> &'static CStr
[src]
unsafe fn initialize_body<'a, W>(
writer: &mut W,
_: &(),
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
[src]
writer: &mut W,
_: &(),
urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
fn create_ref<'a>(raw_data: &'a [u8]) -> Result<&'a Self, ()>
[src]
impl<T> AtomBody for T where
T: 'static + Sized + ScalarAtomBody,
[src]
T: 'static + Sized + ScalarAtomBody,
type InitializationParameter = Self
fn get_uri() -> &'static CStr
[src]
unsafe fn initialize_body<'a, W>(
writer: &mut W,
parameter: &Self,
_urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,
[src]
writer: &mut W,
parameter: &Self,
_urids: &mut CachedMap
) -> Result<(), ()> where
W: WritingFrame<'a> + WritingFrameExt<'a, Self>,