use tracing::instrument;
use super::{Io, State};
#[derive(Debug)]
pub struct Flow {
state: State,
}
impl Flow {
#[instrument(skip_all)]
pub fn new(bytes: impl IntoIterator<Item = u8>) -> Self {
let state = State::new(bytes.into_iter().collect());
Self { state }
}
#[instrument(skip_all)]
pub fn next(&mut self) -> Result<&[u8], Io> {
match self.state.bytes_count.take() {
Some(n) => Ok(&self.state.buffer[..n]),
None => Err(Io::Write),
}
}
}
impl AsMut<State> for Flow {
fn as_mut(&mut self) -> &mut State {
&mut self.state
}
}