use std::fmt; use std::io::{self, SeekFrom}; use std::pin::Pin; use std::task::{Context, Poll};
cfg_io_util! { /// `Empty` ignores any data written via [`AsyncWrite`], and will always be empty /// (returning zero bytes) when read via [`AsyncRead`]. /// /// This struct is generally created by calling [`empty`]. Please see /// the documentation of [`empty()`][`empty`] for more details. /// /// This is an asynchronous version of [`std::io::empty`][std]. /// /// [`empty`]: fn@empty /// [std]: std::io::empty pubstruct Empty {
_p: (),
}
/// Creates a value that is always at EOF for reads, and ignores all data written. /// /// All writes on the returned instance will return `Poll::Ready(Ok(buf.len()))` /// and the contents of the buffer will not be inspected. /// /// All reads from the returned instance will return `Poll::Ready(Ok(0))`. /// /// This is an asynchronous version of [`std::io::empty`][std]. /// /// [std]: std::io::empty /// /// # Examples /// /// A slightly sad example of not reading anything into a buffer: /// /// ``` /// use tokio::io::{self, AsyncReadExt}; /// /// #[tokio::main] /// async fn main() { /// let mut buffer = String::new(); /// io::empty().read_to_string(&mut buffer).await.unwrap(); /// assert!(buffer.is_empty()); /// } /// ``` /// /// A convoluted way of getting the length of a buffer: /// /// ``` /// use tokio::io::{self, AsyncWriteExt}; /// /// #[tokio::main] /// async fn main() { /// let buffer = vec![1, 2, 3, 5, 8]; /// let num_bytes = io::empty().write(&buffer).await.unwrap(); /// assert_eq!(num_bytes, 5); /// } /// ``` pubfn empty() -> Empty {
Empty { _p: () }
}
}
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.