pub mod infinite_lists;
#[cfg(feature = "std")]
pub mod overeager_receivers;
pub trait Stream<X> {
fn head(&self) -> &X;
#[must_use]
fn tail(self) -> Self;
}
#[cfg(feature = "std")]
pub fn print<X, S>(mut stream: S, n: usize) -> S
where
S: Stream<X>,
X: std::fmt::Display,
{
for _ in 0..n {
println!("{}", stream.head());
stream = stream.tail();
}
stream
}
#[cfg(test)]
mod tests {
#[cfg(feature = "std")]
use super::*;
#[cfg(feature = "std")]
use infinite_lists::InfiniteList;
#[macro_export]
macro_rules! assert_head_eq {
($stream:expr, $x:expr) => {
assert_eq!(*$stream.head(), $x);
};
}
#[macro_export]
macro_rules! assert_tail_starts_with {
($stream:expr, $xs:expr) => {
for x in $xs {
$stream = $stream.tail();
assert_head_eq!($stream, x);
}
};
}
#[cfg(feature = "std")]
#[test]
fn test_print() {
let stream = InfiniteList::cons(false, || {
InfiniteList::cons(false, || {
InfiniteList::cons(true, || InfiniteList::constant(true))
})
});
let stream = print(stream, 2);
assert!(stream.head());
}
}