Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
extra functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Veritius committed Jul 5, 2024
1 parent 7698f20 commit 0dfbf5f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions stardust/src/messages/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ impl Message {
self.0.is_empty()
}

/// Returns the message as a slice of bytes.
#[inline]
pub fn as_slice(&self) -> &[u8] {
&self.0
}

/// Attempts to read the message as a string slice.
///
/// This fails if the message is not valid UTF-8.
Expand All @@ -54,6 +60,17 @@ impl Message {
Self(bytes)
}

/// Create a [`Message`] from a static slice of bytes.
#[inline]
pub const fn from_static(slc: &'static [u8]) -> Self {
Self::from_bytes(Bytes::from_static(slc))
}

/// Create a [`Message`] from a static string slice.
#[inline]
pub const fn from_static_str(str: &'static str) -> Self {
Self::from_static(str.as_bytes())
}
}

impl From<Bytes> for Message {
Expand Down

0 comments on commit 0dfbf5f

Please sign in to comment.