mirror of
https://github.com/async-rs/async-std.git
synced 2025-04-12 03:16:43 +00:00
30 lines
861 B
Rust
30 lines
861 B
Rust
use super::IntoStream;
|
|
|
|
use std::pin::Pin;
|
|
|
|
/// Conversion from a `Stream`.
|
|
///
|
|
/// By implementing `FromStream` for a type, you define how it will be created from a stream.
|
|
/// This is common for types which describe a collection of some kind.
|
|
///
|
|
/// See also: [`IntoStream`].
|
|
///
|
|
/// [`IntoStream`]: trait.IntoStream.html
|
|
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
|
#[cfg(any(feature = "unstable", feature = "docs"))]
|
|
pub trait FromStream<T: Send> {
|
|
/// Creates a value from a stream.
|
|
///
|
|
/// # Examples
|
|
///
|
|
/// Basic usage:
|
|
///
|
|
/// ```
|
|
/// // use async_std::stream::FromStream;
|
|
///
|
|
/// // let _five_fives = async_std::stream::repeat(5).take(5);
|
|
/// ```
|
|
fn from_stream<'a, S: IntoStream<Item = T> + Send + 'a>(
|
|
stream: S,
|
|
) -> Pin<Box<dyn core::future::Future<Output = Self> + Send + 'a>>;
|
|
}
|