pub struct FnSource<F, T, E> { /* private fields */ }Expand description
Source adapter over a closure that produces fallible items.
The closure returns Ok(Some(item)) to emit, Ok(None) to signal
end-of-stream, or Err(E) to raise a source error.
§Example
use pipe_io::source::{FnSource, Source};
let mut n = 0u32;
let mut s = FnSource::new(move || -> Result<Option<u32>, &'static str> {
n += 1;
if n <= 3 { Ok(Some(n)) } else { Ok(None) }
});
assert_eq!(s.pull().unwrap(), Some(1));
assert_eq!(s.pull().unwrap(), Some(2));
assert_eq!(s.pull().unwrap(), Some(3));
assert_eq!(s.pull().unwrap(), None);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<F, T, E> Freeze for FnSource<F, T, E>where
F: Freeze,
impl<F, T, E> RefUnwindSafe for FnSource<F, T, E>where
F: RefUnwindSafe,
impl<F, T, E> Send for FnSource<F, T, E>where
F: Send,
impl<F, T, E> Sync for FnSource<F, T, E>where
F: Sync,
impl<F, T, E> Unpin for FnSource<F, T, E>where
F: Unpin,
impl<F, T, E> UnsafeUnpin for FnSource<F, T, E>where
F: UnsafeUnpin,
impl<F, T, E> UnwindSafe for FnSource<F, T, E>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more