Skip to content

Commit

Permalink
This might be better maybe dunno hopefully
Browse files Browse the repository at this point in the history
  • Loading branch information
nabijaczleweli committed Aug 31, 2016
1 parent b32bf86 commit 8c99319
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
13 changes: 0 additions & 13 deletions src/empty.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::marker;

use {Future, Poll};
use stream::Stream;

/// A future which is never resolved.
///
Expand All @@ -28,15 +27,3 @@ impl<T, E> Future for Empty<T, E> {
Poll::NotReady
}
}

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)
}
}
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 8c99319

Please sign in to comment.