/// A `Chain` sequences two buffers. /// /// `Chain` is an adapter that links two underlying buffers and provides a /// continuous view across both buffers. It is able to sequence either immutable /// buffers ([`Buf`] values) or mutable buffers ([`BufMut`] values). /// /// This struct is generally created by calling [`Buf::chain`]. Please see that /// function's documentation for more detail. /// /// # Examples /// /// ``` /// use bytes::{Bytes, Buf}; /// /// let mut buf = (&b"hello "[..]) /// .chain(&b"world"[..]); /// /// let full: Bytes = buf.copy_to_bytes(11); /// assert_eq!(full[..], b"hello world"[..]); /// ``` /// /// [`Buf::chain`]: trait.Buf.html#method.chain /// [`Buf`]: trait.Buf.html /// [`BufMut`]: trait.BufMut.html #[derive(Debug)] pubstruct Chain<T, U> {
a: T,
b: U,
}
impl<T, U> Chain<T, U> { /// Creates a new `Chain` sequencing the provided values. pub(crate) fn new(a: T, b: U) -> Chain<T, U> {
Chain { a, b }
}
/// Gets a reference to the first underlying `Buf`. /// /// # Examples /// /// ``` /// use bytes::Buf; /// /// let buf = (&b"hello"[..]) /// .chain(&b"world"[..]); /// /// assert_eq!(buf.first_ref()[..], b"hello"[..]); /// ``` pubfn first_ref(&self) -> &T {
&self.a
}
/// Gets a mutable reference to the first underlying `Buf`. /// /// # Examples /// /// ``` /// use bytes::Buf; /// /// let mut buf = (&b"hello"[..]) /// .chain(&b"world"[..]); /// /// buf.first_mut().advance(1); /// /// let full = buf.copy_to_bytes(9); /// assert_eq!(full, b"elloworld"[..]); /// ``` pubfn first_mut(&mutself) -> &mut T {
&mutself.a
}
/// Gets a reference to the last underlying `Buf`. /// /// # Examples /// /// ``` /// use bytes::Buf; /// /// let buf = (&b"hello"[..]) /// .chain(&b"world"[..]); /// /// assert_eq!(buf.last_ref()[..], b"world"[..]); /// ``` pubfn last_ref(&self) -> &U {
&self.b
}
/// Gets a mutable reference to the last underlying `Buf`. /// /// # Examples /// /// ``` /// use bytes::Buf; /// /// let mut buf = (&b"hello "[..]) /// .chain(&b"world"[..]); /// /// buf.last_mut().advance(1); /// /// let full = buf.copy_to_bytes(10); /// assert_eq!(full, b"hello orld"[..]); /// ``` pubfn last_mut(&mutself) -> &mut U {
&mutself.b
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.