pub struct Message { /* private fields */ }
Expand description
A message to be communicated between clients.
Contains a MessageKind
, sender UUID, and message UUID.
Implementations§
source§impl Message
impl Message
sourcepub fn new(inner: MessageKind, sender: Uuid, uuid: Uuid) -> Self
pub fn new(inner: MessageKind, sender: Uuid, uuid: Uuid) -> Self
Creates a new message.
sourcepub fn inner(&self) -> &MessageKind
pub fn inner(&self) -> &MessageKind
Get the inner MessageKind
.
This contains all the data of the message.
sourcepub fn inner_mut(&mut self) -> &mut MessageKind
pub fn inner_mut(&mut self) -> &mut MessageKind
Get a mutable reference to the inner MessageKind
.
This contains all the data of the message.
sourcepub fn into_inner(self) -> MessageKind
pub fn into_inner(self) -> MessageKind
Get the inner MessageKind
.
This contains all the data of the message.
sourcepub fn recipient(&self) -> Recipient
pub fn recipient(&self) -> Recipient
Get the specific recipient if the MessageKind
is targeted.
Can be used to determine to send this message to only one pier or all.
sourcepub fn from_bin(slice: &[u8]) -> Result<Self, DecodeError>
pub fn from_bin(slice: &[u8]) -> Result<Self, DecodeError>
§Errors
Returns an appropriate error if the deserialisation failed.
sourcepub fn to_base64(&self) -> String
pub fn to_base64(&self) -> String
Converts the message to a plain text compatible encoding, namely Base64.
This is a optimised version of converting
Self::to_bin()
to Base64. Since I’m using readers and writers, less allocations are needed.
sourcepub fn from_base64(string: &str) -> Result<Self, DecodeError>
pub fn from_base64(string: &str) -> Result<Self, DecodeError>
§Errors
Returns an appropriate error if the deserialisation failed.
If the Base64 encoding is wrong, the error returned is
bincode::error::DecodeError::OtherString
which (always) starts with base64 decoding failed
.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Message
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)