From 91a66c2d94dca7691eb07b51948a2d590212c276 Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Fri, 6 Sep 2019 21:58:53 +0300 Subject: [PATCH] append doc example for io::buf_read::read_until --- src/io/buf_read.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/io/buf_read.rs b/src/io/buf_read.rs index 74242ba..7e6b6fb 100644 --- a/src/io/buf_read.rs +++ b/src/io/buf_read.rs @@ -59,6 +59,29 @@ pub trait BufRead { /// # /// # Ok(()) }) } /// ``` + /// + /// Multiple successful calls to `read_until` append all bytes up to and including to `buf`: + /// ``` + /// # fn main() -> std::io::Result<()> { async_std::task::block_on(async { + /// # + /// use async_std::io::BufReader; + /// use async_std::prelude::*; + /// + /// let from: &[u8] = b"append\nexample\n"; + /// let mut reader = BufReader::new(from); + /// let mut buf = vec![]; + /// + /// let mut size = reader.read_until(b'\n', &mut buf).await?; + /// assert_eq!(size, 7); + /// assert_eq!(buf, b"append\n"); + /// + /// size += reader.read_until(b'\n', &mut buf).await?; + /// assert_eq!(size, from.len()); + /// + /// assert_eq!(buf, from); + /// # + /// # Ok(()) }) } + /// ``` fn read_until<'a>( &'a mut self, byte: u8,