pub trait Atom<'a, 'b>: UriBoundwhere
'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§
Sourcetype ReadParameter
type ReadParameter
The atom-specific parameter of the read function.
If your atom does not need a reading parameter, you may set it to ().
Sourcetype ReadHandle: 'a
type ReadHandle: 'a
The return value of the read function.
It may contain a reference to the atom and therefore may not outlive it.
Sourcetype WriteParameter
type WriteParameter
The atom-specific parameter of the write function.
If your atom does not need a writing parameter, you may set it to ().
Sourcetype WriteHandle: 'b
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§
Sourcefn read(
body: Space<'a>,
parameter: Self::ReadParameter,
) -> Option<Self::ReadHandle>
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.
Sourcefn init(
frame: FramedMutSpace<'a, 'b>,
parameter: Self::WriteParameter,
) -> Option<Self::WriteHandle>
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.