1use tracing::instrument;
2
3use super::{Io, State};
4
5#[derive(Debug)]
12pub struct Flow {
13 state: State,
14}
15
16impl Flow {
17 #[instrument(skip_all)]
19 pub fn new() -> Self {
20 let state = State::new();
21 Self { state }
22 }
23
24 #[instrument(skip_all)]
26 pub fn with_capacity(capacity: usize) -> Self {
27 let state = State::with_capacity(capacity);
28 Self { state }
29 }
30
31 #[instrument(skip_all)]
32 pub fn next(&mut self) -> Result<&[u8], Io> {
33 match self.state.bytes_count.take() {
34 Some(n) => Ok(&self.state.buffer[..n]),
35 None => Err(Io::Read),
36 }
37 }
38}
39
40impl AsMut<State> for Flow {
41 fn as_mut(&mut self) -> &mut State {
42 &mut self.state
43 }
44}