Trait lunatic::Message [−][src]
pub trait Message { fn from_bincode(data: &[u8], resources: &[u64]) -> (usize, Self); unsafe fn to_bincode(self, dest: &mut Vec<u8>); }
Expand description
A primitive for exchanging data between processes.
When a Message
is sent to another process all the data is copied, as processes don’t
share any memory space. Every type that implements serde::Serialize
and
serde::Deserialize
automatically implements Message
.
Lunatic resources (Process
, TcpStream
,
…) are owned by processes and some extra steps need to be taken when sending them between
processes. To simplify implementing Message
for types that hold lunatic resources, a derive
macro is provided lunatic::derive::Message
.
Required methods
Returns bytes read from data and the deserialized value.
unsafe fn to_bincode(self, dest: &mut Vec<u8>)
unsafe fn to_bincode(self, dest: &mut Vec<u8>)
Consumes itself and writes the serialized representation to dest.
Safety
Some lunatic resources will add themself to the next message and only write their index
inside of the resource array to dest
. If not handled correctly, this can lead to resource
leaks. This method should never be implemented manually, instead you should use:
#[derive(serde::Serialize, serde::Deserialize)]
or #[derive(lunatic::derive::Message)]