Skip to main content

Step

Struct Step 

Source
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:

consumedeventmeaning
0Nonestop. A partial preface or a partial frame; read more input before calling again.
> 0Nonekeep 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.
> 0Somean 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§

Source§

impl<'a> Debug for Step<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.