From 5a5586a1959610347bb7122d97a70613be021fdf Mon Sep 17 00:00:00 2001 From: Daniel Abramov Date: Fri, 13 Dec 2024 19:58:52 +0100 Subject: [PATCH] payload: inline functions --- src/protocol/frame/payload.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/protocol/frame/payload.rs b/src/protocol/frame/payload.rs index fa4d5741..fac722c3 100644 --- a/src/protocol/frame/payload.rs +++ b/src/protocol/frame/payload.rs @@ -13,6 +13,7 @@ pub enum Payload { impl Payload { /// Returns a slice of the payload. + #[inline] pub fn as_slice(&self) -> &[u8] { match self { Payload::Owned(v) => v, @@ -26,6 +27,7 @@ impl Payload { /// and there are other references to the same data. No allocation /// would happen if the payload is owned or if there is only one /// `Bytes` instance referencing the data. + #[inline] pub fn as_mut_slice(&mut self) -> &mut [u8] { match self { Payload::Owned(v) => &mut *v, @@ -43,12 +45,14 @@ impl Payload { } /// Returns the length of the payload. + #[inline] #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { self.as_slice().len() } /// Consumes the payload and returns the underlying data as a vector. + #[inline] pub fn into_data(self) -> Vec { match self { Payload::Owned(v) => v, @@ -57,6 +61,7 @@ impl Payload { } /// Consumes the payload and returns the underlying data as a string. + #[inline] pub fn into_text(self) -> Result { match self { Payload::Owned(v) => Ok(String::from_utf8(v)?), @@ -73,7 +78,7 @@ impl From> for Payload { impl From for Payload { fn from(v: String) -> Self { - Payload::Owned(v.into_bytes()) + Payload::Owned(v.into()) } }