Atom

Trait Atom 

Source
pub trait Atom<'a, 'b>: UriBound
where 'a: 'b,
{ type ReadParameter; type ReadHandle: 'a; type WriteParameter; type WriteHandle: 'b; // Required methods fn read( body: Space<'a>, parameter: Self::ReadParameter, ) -> Option<Self::ReadHandle>; fn init( frame: FramedMutSpace<'a, 'b>, parameter: Self::WriteParameter, ) -> Option<Self::WriteHandle>; }
Expand description

Atom type.

This is the foundation of this crate: Types that implement Atom define the reading and writing functions for an atom type. However, these types will never be constructed; They are only names to be used for generic type arguments.

This trait has two lifetime parameters: The first one is the lifetime of the atom in memory. In practice, this will often be 'static, but it’s good to keep it generic for testing purposes. The second parameter is the lifetime of the MutSpace borrowed by the FramedMutSpace parameter in the write method. Since the WriteParameter may contain this FramedMutSpace, it has to be assured that it lives long enough. Since the referenced MutSpace also has to borrow the atom, it may not live longer than the atom.

Required Associated Types§

Source

type ReadParameter

The atom-specific parameter of the read function.

If your atom does not need a reading parameter, you may set it to ().

Source

type ReadHandle: 'a

The return value of the read function.

It may contain a reference to the atom and therefore may not outlive it.

Source

type WriteParameter

The atom-specific parameter of the write function.

If your atom does not need a writing parameter, you may set it to ().

Source

type WriteHandle: 'b

The return value of the write function.

It may contain a reference to a MutSpace and therefore may not outlive it.

Required Methods§

Source

fn read( body: Space<'a>, parameter: Self::ReadParameter, ) -> Option<Self::ReadHandle>

Read the body of the atom.

The passed space exactly covers the body of the atom, excluding the header. You may assume that the body is actually of your atom type, since the URID of the atom was checked beforehand.

If the atom is malformed, you may not panic and return None instead.

Source

fn init( frame: FramedMutSpace<'a, 'b>, parameter: Self::WriteParameter, ) -> Option<Self::WriteHandle>

Initialize the body of the atom.

In this method, the atom is prepared for the writing handle. Usually, the atom will not be valid when initializied; Users have to use the write handle to make it valid.

The frame of the atom was already initialized, containing the URID.

If space is insufficient, you may not panic and return None instead. The written results are assumed to be malformed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a, 'b> Atom<'a, 'b> for Chunk
where 'a: 'b,

Source§

impl<'a, 'b> Atom<'a, 'b> for Blank
where 'a: 'b,

Source§

impl<'a, 'b> Atom<'a, 'b> for Object
where 'a: 'b,

Source§

impl<'a, 'b> Atom<'a, 'b> for Sequence
where 'a: 'b,

Source§

impl<'a, 'b> Atom<'a, 'b> for Literal
where 'a: 'b,

Source§

impl<'a, 'b> Atom<'a, 'b> for String
where 'a: 'b,

Source§

impl<'a, 'b> Atom<'a, 'b> for Tuple
where 'a: 'b,

Source§

impl<'a, 'b, A: ScalarAtom> Atom<'a, 'b> for A
where 'a: 'b,

Source§

impl<'a, 'b, C> Atom<'a, 'b> for Vector<C>
where C: 'b + ScalarAtom, 'a: 'b,