Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/headers/src/util/   (Firefox Browser Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 2 kB image not shown  

Quelle  value_string.rs

  Sprache: Rust
 

use std::{
    fmt,
    str::{self, FromStr},
};

use bytes::Bytes;
use http::header::HeaderValue;

use super::IterExt;

/// A value that is both a valid `HeaderValue` and `String`.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub(cratestruct 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,
}

impl HeaderValueString {
    pub(cratefn from_val(val: &HeaderValue) -> Result<Self, ::Error> {
        if val.to_str().is_ok() {
            Ok(HeaderValueString { value: val.clone() })
        } else {
            Err(::Error::invalid())
        }
    }

    pub(cratefn 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(cratefn from_static(src: &'static str) -> HeaderValueString {
        // A valid `str` (the argument)...
        HeaderValueString {
            value: HeaderValue::from_static(src),
        }
    }

    pub(cratefn 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()) }
    }
}

impl fmt::Debug for HeaderValueString {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        fmt::Debug::fmt(self.as_str(), f)
    }
}

impl fmt::Display for HeaderValueString {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        fmt::Display::fmt(self.as_str(), f)
    }
}

impl super::TryFromValues for HeaderValueString {
    fn try_from_values<'i, I>(values: &mut I) -> Result<Self, ::Error>
    where
        I: Iterator<Item = &'i HeaderValue>,
    {
        values
            .just_one()
            .map(HeaderValueString::from_val)
            .unwrap_or_else(|| Err(::Error::invalid()))
    }
}

impl<'a> From<&'a HeaderValueString> for HeaderValue {
    fn from(src: &'a HeaderValueString) -> HeaderValue {
        src.value.clone()
    }
}

#[derive(Debug)]
pub(cratestruct FromStrError(());

impl FromStr for HeaderValueString {
    type Err = FromStrError;

    fn from_str(src: &str) -> Result<SelfSelf::Err> {
        // A valid `str` (the argument)...
        src.parse()
            .map(|value| HeaderValueString { value })
            .map_err(|_| FromStrError(()))
    }
}

Messung V0.5 in Prozent
C=91 H=97 G=93

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-06-22) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

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.