pub struct Message {
pub(crate) data: Bytes,
pub(crate) compressed: bool,
}Expand description
Fields§
§data: Bytes§compressed: boolImplementations§
Source§impl Message
impl Message
Sourcepub fn serialize<M: Serialize + ?Sized>(
message: &M,
stream_params: StreamParams,
) -> Self
pub fn serialize<M: Serialize + ?Sized>( message: &M, stream_params: StreamParams, ) -> Self
This serializes any message, according to the Streams Promises.
You can reuse this Message and send it via other Streams, if the
Promises match. E.g. Sending a Message via a compressed and
uncompressed Stream is dangerous, unless the remote site knows about
this.
§Example
for example coding, see send_raw
Sourcepub fn deserialize<M: DeserializeOwned>(self) -> Result<M, StreamError>
pub fn deserialize<M: DeserializeOwned>(self) -> Result<M, StreamError>
deserialize this Message. This consumes the struct, as deserialization
is only expected once. Use this when deserialize a recv_raw
Message. If you are resending this message, deserialization might need
to copy memory
§Example
// Create a Network, listen on Port `2300` and wait for a Stream to be opened, then listen on it
let mut stream_a = participant_a.opened().await?;
//Recv Message
let msg = stream_a.recv_raw().await?;
println!("Msg is {}", msg.deserialize::<String>()?);
drop(network);pub(crate) fn verify(&self, params: StreamParams)
Auto Trait Implementations§
impl !Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more