/// A value that is both a valid `HeaderValue` and `String`. #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub(crate) struct HeaderValueString { /// Care must be taken to only set this value when it is also /// a valid `String`, since `as_str` will convert to a `&str` /// in an unchecked manner.
value: HeaderValue,
}
pub(crate) fn from_string(src: String) -> Option<Self> { // A valid `str` (the argument)... let bytes = Bytes::from(src);
HeaderValue::from_maybe_shared(bytes)
.ok()
.map(|value| HeaderValueString { value })
}
pub(crate) fn from_static(src: &'static str) -> HeaderValueString { // A valid `str` (the argument)...
HeaderValueString {
value: HeaderValue::from_static(src),
}
}
pub(crate) fn as_str(&self) -> &str { // HeaderValueString is only created from HeaderValues // that have validated they are also UTF-8 strings. unsafe { str::from_utf8_unchecked(self.value.as_bytes()) }
}
}
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.