use tracing::instrument;
use super::{Io, State};
#[derive(Debug)]
pub struct Flow {
state: State,
}
impl Flow {
#[instrument(skip_all)]
pub fn new() -> Self {
let state = State::new();
Self { state }
}
#[instrument(skip_all)]
pub fn with_capacity(capacity: usize) -> Self {
let state = State::with_capacity(capacity);
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::Read),
}
}
}
impl AsMut<State> for Flow {
fn as_mut(&mut self) -> &mut State {
&mut self.state
}
}