diff --git a/tokio-util/src/codec/length_delimited.rs b/tokio-util/src/codec/length_delimited.rs index abc6461b5..e114426c2 100644 --- a/tokio-util/src/codec/length_delimited.rs +++ b/tokio-util/src/codec/length_delimited.rs @@ -679,18 +679,21 @@ impl Builder { /// # Examples /// /// ``` - /// # use tokio::io::AsyncRead; /// use tokio_util::codec::LengthDelimitedCodec; + /// use tokio_stream::StreamExt; /// - /// # fn bind_read(io: T) { - /// LengthDelimitedCodec::builder() + /// # #[tokio::main(flavor = "current_thread")] + /// # async fn main() { + /// let io: &[u8] = b"\x00\x0bhello world"; + /// let mut reader = LengthDelimitedCodec::builder() /// .length_field_offset(0) /// .length_field_type::() /// .length_adjustment(0) - /// .num_skip(0) /// .new_read(io); + /// + /// let frame = reader.next().await.unwrap().unwrap(); + /// assert_eq!(&frame[..], b"hello world"); /// # } - /// # pub fn main() {} /// ``` pub fn new() -> Builder { Builder { @@ -953,14 +956,20 @@ impl Builder { /// # Examples /// /// ``` - /// use tokio_util::codec::LengthDelimitedCodec; + /// use bytes::{Bytes, BytesMut}; + /// use tokio_util::codec::{Decoder, Encoder, LengthDelimitedCodec}; + /// /// # pub fn main() { - /// LengthDelimitedCodec::builder() + /// let mut codec = LengthDelimitedCodec::builder() /// .length_field_offset(0) /// .length_field_type::() /// .length_adjustment(0) - /// .num_skip(0) /// .new_codec(); + /// + /// let mut buf = BytesMut::new(); + /// codec.encode(Bytes::from_static(b"hello world"), &mut buf).unwrap(); + /// let frame = codec.decode(&mut buf).unwrap().unwrap(); + /// assert_eq!(&frame[..], b"hello world"); /// # } /// ``` pub fn new_codec(&self) -> LengthDelimitedCodec { @@ -979,18 +988,21 @@ impl Builder { /// # Examples /// /// ``` - /// # use tokio::io::AsyncRead; /// use tokio_util::codec::LengthDelimitedCodec; + /// use tokio_stream::StreamExt; /// - /// # fn bind_read(io: T) { - /// LengthDelimitedCodec::builder() + /// # #[tokio::main(flavor = "current_thread")] + /// # async fn main() { + /// let io: &[u8] = b"\x00\x0bhello world"; + /// let mut reader = LengthDelimitedCodec::builder() /// .length_field_offset(0) /// .length_field_type::() /// .length_adjustment(0) - /// .num_skip(0) /// .new_read(io); + /// + /// let frame = reader.next().await.unwrap().unwrap(); + /// assert_eq!(&frame[..], b"hello world"); /// # } - /// # pub fn main() {} /// ``` pub fn new_read(&self, upstream: T) -> FramedRead where