diff --git a/channels-io/src/buf.rs b/channels-io/src/buf.rs index e1317a0..023d7ce 100644 --- a/channels-io/src/buf.rs +++ b/channels-io/src/buf.rs @@ -17,6 +17,7 @@ impl BaseBuf { impl> BaseBuf { /// Get a reference to the entire buffer. #[inline] + #[must_use] pub fn inner(&self) -> &[u8] { self.inner.as_ref() } @@ -64,6 +65,7 @@ impl> BaseBuf { impl> BaseBuf { /// Get a mutable reference to the entire buffer. #[inline] + #[must_use] pub fn inner_mut(&mut self) -> &mut [u8] { self.inner.as_mut() } diff --git a/channels/src/lib.rs b/channels/src/lib.rs index 13b0f01..553123d 100644 --- a/channels/src/lib.rs +++ b/channels/src/lib.rs @@ -126,6 +126,7 @@ pub type Pair = (Sender, Receiver); /// let received: i32 = rx.recv().await.unwrap(); /// } /// ``` +#[inline] pub fn channel( r: impl io::IntoRead, w: impl io::IntoWrite, diff --git a/channels/src/receiver.rs b/channels/src/receiver.rs index 95b5979..35a0420 100644 --- a/channels/src/receiver.rs +++ b/channels/src/receiver.rs @@ -38,7 +38,7 @@ impl Receiver { /// .deserializer(deserializer) /// .build(); /// ``` - #[must_use] + #[inline] pub fn builder() -> Builder { Builder::new() } @@ -68,6 +68,7 @@ impl Receiver { /// ``` /// /// [`Bincode`]: crate::serdes::Bincode + #[inline] pub fn new(reader: impl IntoRead) -> Self { Self::with_deserializer(reader, crate::serdes::Bincode::new()) } @@ -104,6 +105,7 @@ impl Receiver { /// deserializer /// ); /// ``` + #[inline] pub fn with_deserializer( reader: impl IntoRead, deserializer: D, @@ -136,6 +138,7 @@ impl Receiver { /// println!("{:#?}", rx.config()); /// /// ``` + #[inline] pub fn config(&self) -> &Config { &self.config } @@ -181,6 +184,7 @@ impl Receiver { /// } /// } /// ``` + #[inline] pub fn incoming(&mut self) -> Incoming<'_, T, R, D> { Incoming { receiver: self } } @@ -198,6 +202,7 @@ impl Receiver { /// assert_eq!(stats.packets(), 0); /// assert_eq!(stats.ops(), 0); /// ``` + #[inline] #[cfg(feature = "statistics")] pub fn statistics(&self) -> &Statistics { &self.reader.statistics @@ -231,6 +236,7 @@ where /// let r: &MyReader = rx.get(); /// assert_eq!(r.count, 42); /// ``` + #[inline] pub fn get(&self) -> &R::Inner { self.reader.inner.get_ref() } @@ -260,11 +266,13 @@ where /// r.count += 10; /// assert_eq!(r.count, 52); /// ``` + #[inline] pub fn get_mut(&mut self) -> &mut R::Inner { self.reader.inner.get_mut() } /// Destruct the receiver and get back the underlying reader. + #[inline] pub fn into_reader(self) -> R::Inner { self.reader.inner.into_inner() } @@ -395,6 +403,7 @@ where /// A builder for [`Receiver`]. #[derive(Clone)] +#[must_use = "builders don't do anything unless you `.build()` them"] pub struct Builder { _marker: PhantomData T>, reader: R, @@ -416,7 +425,7 @@ impl Builder { /// .deserializer(deserializer) /// .build(); /// ``` - #[must_use] + #[inline] pub fn new() -> Self { Builder { _marker: PhantomData, @@ -428,6 +437,7 @@ impl Builder { } impl Default for Builder { + #[inline] fn default() -> Self { Self::new() } @@ -453,6 +463,7 @@ impl Builder { /// let builder = channels::Receiver::::builder() /// .reader(tokio::io::empty()); /// ``` + #[inline] pub fn reader( self, reader: impl IntoRead, @@ -477,6 +488,7 @@ impl Builder { /// let builder = channels::Receiver::::builder() /// .deserializer(deserializer); /// ``` + #[inline] pub fn deserializer( self, deserializer: D, @@ -504,7 +516,7 @@ impl Builder { /// let rx = Receiver::::builder() /// .config(config); /// ``` - #[must_use] + #[inline] pub fn config(mut self, config: Config) -> Self { self.config = Some(config); self @@ -520,6 +532,7 @@ impl Builder { /// .deserializer(channels::serdes::Bincode::new()) /// .build(); /// ``` + #[inline] pub fn build(self) -> Receiver { Receiver { _marker: PhantomData, @@ -620,6 +633,7 @@ impl Builder { /// [`Sender`]: crate::Sender /// [`use_header_checksum()`]: crate::sender::Config::use_header_checksum() #[derive(Clone)] +#[must_use = "`Config`s don't do anything on their own"] pub struct Config { pub(crate) size_estimate: Option, pub(crate) max_size: Option, @@ -627,6 +641,7 @@ pub struct Config { } impl Default for Config { + #[inline] fn default() -> Self { Self { size_estimate: None, @@ -641,6 +656,7 @@ impl Default for Config { impl Config { /// Get the size estimate of the [`Receiver`]. + #[inline] #[must_use] pub fn size_estimate(&self) -> usize { self.size_estimate.map_or(0, NonZeroUsize::get) @@ -648,6 +664,7 @@ impl Config { /// Set the size estimate of the [`Receiver`]. #[allow(clippy::missing_panics_doc)] + #[inline] pub fn set_size_estimate( &mut self, estimate: usize, @@ -663,13 +680,14 @@ impl Config { } /// Set the size estimate of the [`Receiver`]. - #[must_use] + #[inline] pub fn with_size_estimate(mut self, estimate: usize) -> Self { self.set_size_estimate(estimate); self } /// Get the max size of the [`Receiver`]. + #[inline] #[must_use] pub fn max_size(&self) -> usize { self.max_size.map_or(0, NonZeroUsize::get) @@ -677,6 +695,7 @@ impl Config { /// Set the max size of the [`Receiver`]. #[allow(clippy::missing_panics_doc)] + #[inline] pub fn set_max_size(&mut self, max_size: usize) -> &mut Self { self.max_size = match max_size { 0 => None, @@ -689,7 +708,7 @@ impl Config { } /// Set the max size of the [`Receiver`]. - #[must_use] + #[inline] pub fn with_max_size(mut self, max_size: usize) -> Self { self.set_max_size(max_size); self @@ -697,12 +716,14 @@ impl Config { /// Get whether the [`Receiver`] will verify each packet's header with the /// checksum. + #[inline] #[must_use] pub fn verify_header_checksum(&self) -> bool { self.verify_header_checksum } /// Whether to verify each packet's header with the checksum. + #[inline] pub fn set_verify_header_checksum( &mut self, yes: bool, @@ -712,7 +733,7 @@ impl Config { } /// Whether to verify each packet's header with the checksum. - #[must_use] + #[inline] pub fn with_verify_header_checksum(mut self, yes: bool) -> Self { self.set_verify_header_checksum(yes); self diff --git a/channels/src/sender.rs b/channels/src/sender.rs index cb3feae..8e2556b 100644 --- a/channels/src/sender.rs +++ b/channels/src/sender.rs @@ -4,6 +4,8 @@ use core::borrow::Borrow; use core::fmt; use core::marker::PhantomData; +use alloc::vec::Vec; + use crate::error::SendError; use crate::io::{AsyncWrite, Container, IntoWrite, Write}; use crate::protocol::Pcb; @@ -36,7 +38,7 @@ impl Sender { /// .serializer(serializer) /// .build(); /// ``` - #[must_use] + #[inline] pub fn builder() -> Builder { Builder::new() } @@ -66,6 +68,7 @@ impl Sender { /// ``` /// /// [`Bincode`]: crate::serdes::Bincode + #[inline] pub fn new(writer: impl IntoWrite) -> Self { Self::with_serializer(writer, crate::serdes::Bincode::new()) } @@ -102,6 +105,7 @@ impl Sender { /// serializer /// ); /// ``` + #[inline] pub fn with_serializer( writer: impl IntoWrite, serializer: S, @@ -134,6 +138,7 @@ impl Sender { /// println!("{:#?}", rx.config()); /// /// ``` + #[inline] pub fn config(&self) -> &Config { &self.config } @@ -151,6 +156,7 @@ impl Sender { /// assert_eq!(stats.packets(), 0); /// assert_eq!(stats.ops(), 0); /// ``` + #[inline] #[cfg(feature = "statistics")] pub fn statistics(&self) -> &Statistics { &self.writer.statistics @@ -188,6 +194,7 @@ where /// let w: &MyWriter = tx.get(); /// assert_eq!(w.count, 42); /// ``` + #[inline] pub fn get(&self) -> &W::Inner { self.writer.inner.get_ref() } @@ -221,11 +228,13 @@ where /// w.count += 10; /// assert_eq!(w.count, 52); /// ``` + #[inline] pub fn get_mut(&mut self) -> &mut W::Inner { self.writer.inner.get_mut() } /// Destruct the sender and get back the underlying writer. + #[inline] pub fn into_writer(self) -> W::Inner { self.writer.inner.into_inner() } @@ -353,6 +362,7 @@ where /// A builder for [`Sender`]. #[derive(Clone)] +#[must_use = "builders don't do anything unless you `.build()` them"] pub struct Builder { _marker: PhantomData T>, writer: W, @@ -374,7 +384,7 @@ impl Builder { /// .serializer(serializer) /// .build(); /// ``` - #[must_use] + #[inline] pub fn new() -> Self { Builder { _marker: PhantomData, @@ -386,6 +396,7 @@ impl Builder { } impl Default for Builder { + #[inline] fn default() -> Self { Self::new() } @@ -411,6 +422,7 @@ impl Builder { /// let builder = channels::Sender::::builder() /// .writer(tokio::io::sink()); /// ``` + #[inline] pub fn writer( self, writer: impl IntoWrite, @@ -435,6 +447,7 @@ impl Builder { /// let builder = channels::Sender::::builder() /// .serializer(serializer); /// ``` + #[inline] pub fn serializer(self, serializer: S) -> Builder { Builder { _marker: PhantomData, @@ -459,7 +472,7 @@ impl Builder { /// let tx = Sender::::builder() /// .config(config); /// ``` - #[must_use] + #[inline] pub fn config(mut self, config: Config) -> Self { self.config = Some(config); self @@ -475,6 +488,7 @@ impl Builder { /// .serializer(channels::serdes::Bincode::new()) /// .build(); /// ``` + #[inline] pub fn build(self) -> Sender { Sender { _marker: PhantomData, @@ -549,6 +563,7 @@ impl Builder { /// /// [`write()`]: Write::write() #[derive(Clone)] +#[must_use = "`Config`s don't do anything on their own"] pub struct Config { flags: u8, } @@ -574,6 +589,7 @@ impl Config { } impl Default for Config { + #[inline] fn default() -> Self { Self { flags: Self::FLUSH_ON_SEND @@ -585,31 +601,35 @@ impl Default for Config { impl Config { /// Get whether the [`Sender`] will flush the writer after every send. + #[inline] #[must_use] pub fn flush_on_send(&self) -> bool { self.get_flag(Self::FLUSH_ON_SEND) } /// Whether the [`Sender`] will flush the writer after every send. + #[inline] pub fn set_flush_on_send(&mut self, yes: bool) -> &mut Self { self.set_flag(Self::FLUSH_ON_SEND, yes); self } /// Whether the [`Sender`] will flush the writer after every send. - #[must_use] + #[inline] pub fn with_flush_on_send(mut self, yes: bool) -> Self { self.set_flush_on_send(yes); self } /// Get whether the [`Sender`] will calculate the checksum for sent packets. + #[inline] #[must_use] pub fn use_header_checksum(&self) -> bool { self.get_flag(Self::USE_HEADER_CHECKSUM) } /// Whether the [`Sender`] will calculate the checksum for sent packets. + #[inline] pub fn set_use_header_checksum( &mut self, yes: bool, @@ -619,26 +639,28 @@ impl Config { } /// Whether the [`Sender`] will calculate the checksum for sent packets. - #[must_use] + #[inline] pub fn with_use_header_checksum(mut self, yes: bool) -> Self { self.set_use_header_checksum(yes); self } /// Get whether the [`Sender`] will coalesce all writes into a single buffer. + #[inline] #[must_use] pub fn coalesce_writes(&self) -> bool { self.get_flag(Self::COALESCE_WRITES) } /// Whether the [`Sender`] will coalesce all writes into a single buffer. + #[inline] pub fn set_coalesce_writes(&mut self, yes: bool) -> &mut Self { self.set_flag(Self::COALESCE_WRITES, yes); self } /// Whether the [`Sender`] will coalesce all writes into a single buffer. - #[must_use] + #[inline] pub fn with_coalesce_writes(mut self, yes: bool) -> Self { self.set_coalesce_writes(yes); self diff --git a/channels/src/util.rs b/channels/src/util.rs index 38cf09d..24d3473 100644 --- a/channels/src/util.rs +++ b/channels/src/util.rs @@ -39,18 +39,21 @@ impl Statistics { #[allow(dead_code)] impl Statistics { /// Returns the number of bytes transferred through this reader/writer. + #[inline] #[must_use] pub fn total_bytes(&self) -> u64 { self.total_bytes } /// Returns the number of packets transferred through this reader/writer. + #[inline] #[must_use] pub fn packets(&self) -> u64 { self.packets } /// Returns the total number of `send`/`recv` operations. + #[inline] #[must_use] pub fn ops(&self) -> u64 { self.ops