Skip to content

Commit

Permalink
Merge pull request rust-lang#114 from nabijaczleweli/master
Browse files Browse the repository at this point in the history
Implement Stream for Empty
  • Loading branch information
alexcrichton authored Aug 31, 2016
2 parents 8677afc + 8c99319 commit 33199e0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/stream/empty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use core::marker;

use stream::Stream;
use Poll;

/// A stream which is never resolved.
///
/// This stream can be created with the `stream::empty` function.
pub struct Empty<T, E> {
_data: marker::PhantomData<(T, E)>,
}

/// Creates a stream which never resolves, representing a computation that never
/// finishes.
///
/// The returned stream will never resolve with a value but is still
/// susceptible to cancellation. That is, if a callback is scheduled on the
/// returned stream, it is only run once the stream is dropped (canceled).
pub fn empty<T, E>() -> Empty<T, E> {
Empty { _data: marker::PhantomData }
}

impl<T, E> Stream for Empty<T, E>
where T: Send + 'static,
E: Send + 'static
{
type Item = T;
type Error = E;

fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
Poll::Ok(None)
}
}
2 changes: 2 additions & 0 deletions src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod iter;
pub use self::iter::{iter, IterStream};

mod and_then;
mod empty;
mod filter;
mod filter_map;
mod flatten;
Expand All @@ -35,6 +36,7 @@ mod take;
mod then;
mod zip;
pub use self::and_then::AndThen;
pub use self::empty::{Empty, empty};
pub use self::filter::Filter;
pub use self::filter_map::FilterMap;
pub use self::flatten::Flatten;
Expand Down

0 comments on commit 33199e0

Please sign in to comment.