/// A frame of any kind related to an HTTP stream (body). #[derive(Debug)] pubstruct Frame<T> {
kind: Kind<T>,
}
#[derive(Debug)] enum Kind<T> { // The first two variants are "inlined" since they are undoubtedly // the most common. This saves us from having to allocate a // boxed trait object for them.
Data(T),
Trailers(HeaderMap), //Unknown(Box<dyn Frameish>),
}
impl<T> Frame<T> { /// Create a DATA frame with the provided `Buf`. pubfn data(buf: T) -> Self { Self {
kind: Kind::Data(buf),
}
}
/// Maps this frame's data to a different type. pubfn map_data<F, D>(self, f: F) -> Frame<D> where
F: FnOnce(T) -> D,
{ matchself.kind {
Kind::Data(data) => Frame {
kind: Kind::Data(f(data)),
},
Kind::Trailers(trailers) => Frame {
kind: Kind::Trailers(trailers),
},
}
}
/// Returns whether this is a DATA frame. pubfn is_data(&self) -> bool {
matches!(self.kind, Kind::Data(..))
}
/// Consumes self into the buf of the DATA frame. /// /// Returns an [`Err`] containing the original [`Frame`] when frame is not a DATA frame. /// `Frame::is_data` can also be used to determine if the frame is a DATA frame. pubfn into_data(self) -> Result<T, Self> { matchself.kind {
Kind::Data(data) => Ok(data),
_ => Err(self),
}
}
/// If this is a DATA frame, returns a reference to it. /// /// Returns `None` if not a DATA frame. pubfn data_ref(&self) -> Option<&T> { matchself.kind {
Kind::Data(ref data) => Some(data),
_ => None,
}
}
/// If this is a DATA frame, returns a mutable reference to it. /// /// Returns `None` if not a DATA frame. pubfn data_mut(&mutself) -> Option<&mut T> { matchself.kind {
Kind::Data(refmut data) => Some(data),
_ => None,
}
}
/// Returns whether this is a trailers frame. pubfn is_trailers(&self) -> bool {
matches!(self.kind, Kind::Trailers(..))
}
/// Consumes self into the buf of the trailers frame. /// /// Returns an [`Err`] containing the original [`Frame`] when frame is not a trailers frame. /// `Frame::is_trailers` can also be used to determine if the frame is a trailers frame. pubfn into_trailers(self) -> Result<HeaderMap, Self> { matchself.kind {
Kind::Trailers(trailers) => Ok(trailers),
_ => Err(self),
}
}
/// If this is a trailers frame, returns a reference to it. /// /// Returns `None` if not a trailers frame. pubfn trailers_ref(&self) -> Option<&HeaderMap> { matchself.kind {
Kind::Trailers(ref trailers) => Some(trailers),
_ => None,
}
}
/// If this is a trailers frame, returns a mutable reference to it. /// /// Returns `None` if not a trailers frame. pubfn trailers_mut(&mutself) -> Option<&mut HeaderMap> { matchself.kind {
Kind::Trailers(refmut trailers) => Some(trailers),
_ => None,
}
}
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.14Bemerkung:
(vorverarbeitet am 2026-10-01)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.