pub struct Step<'a> {
pub consumed: usize,
pub event: Option<Event<'a>>,
}Expand description
One decode step: how much of input was consumed, and the event it
produced, if any. See the step contract.
consumed and event are independent. All three shapes are normal:
consumed | event | meaning |
|---|---|---|
0 | None | stop. A partial preface or a partial frame; read more input before calling again. |
> 0 | None | keep going. Progress with nothing for the host: the client preface, PRIORITY, an unknown frame type, or a frame the peer had in flight for a stream that is already gone. |
> 0 | Some | an event. In HTTP/2 an event always consumes; consumed == 0 is only ever the stop case. |
So the loop condition is consumed > 0 || event.is_some():
loop {
let step = connection.receive(&input)?;
let consumed = step.consumed;
let progressed = consumed > 0 || step.event.is_some();
if let Some(event) = step.event {
// DATA borrows `input`, so handle the event before draining.
let _ = event;
}
input.drain(..consumed);
if !progressed {
break; // read more bytes from the transport, then continue
}
}Looping while event.is_some() instead stalls at the client preface —
the first step of every server connection, before a single frame is read.
Looping while input remains spins forever on a partial frame.
Fields§
§consumed: usize§event: Option<Event<'a>>Trait Implementations§
Auto Trait Implementations§
impl<'a> Forget for Step<'a>
impl<'a> Freeze for Step<'a>
impl<'a> RefUnwindSafe for Step<'a>
impl<'a> Send for Step<'a>
impl<'a> Sync for Step<'a>
impl<'a> Unpin for Step<'a>
impl<'a> UnsafeUnpin for Step<'a>
impl<'a> UnwindSafe for Step<'a>
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