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

Quelle  fixed.rs

  Sprache: Rust
 

// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

//! Data provider always serving the same struct.

use core::fmt;
use icu_provider::prelude::*;
use yoke::Yokeable;

/// A data provider that returns clones of a fixed type-erased payload.
///
/// # Examples
///
/// ```
/// use icu_provider::hello_world::*;
/// use icu_provider::prelude::*;
/// use icu_provider_adapters::fixed::FixedProvider;
/// use std::borrow::Cow;
/// use writeable::assert_writeable_eq;
///
/// let provider = FixedProvider::<HelloWorldV1>::from_static(&HelloWorld {
///     message: Cow::Borrowed("custom hello world"),
/// });
///
/// // Check that it works:
/// let formatter =
///     HelloWorldFormatter::try_new_unstable(&provider, Default::default())
///         .expect("marker matches");
/// assert_writeable_eq!(formatter.format(), "custom hello world");
/// ```
#[allow(clippy::exhaustive_structs)] // this type is stable
pub struct FixedProvider<M: DataMarker> {
    data: DataPayload<M>,
}

impl<M: DataMarker> FixedProvider<M> {
    /// Creates a `FixedProvider` with an owned (allocated) payload of the given data.
    pub fn from_owned(data: M::DataStruct) -> Self {
        Self::from_payload(DataPayload::from_owned(data))
    }

    /// Creates a `FixedProvider` with a statically borrowed payload of the given data.
    pub fn from_static(data: &'static M::DataStruct) -> Self {
        FixedProvider {
            data: DataPayload::from_static_ref(data),
        }
    }

    /// Creates a `FixedProvider` from an existing [`DataPayload`].
    pub fn from_payload(data: DataPayload<M>) -> Self {
        FixedProvider { data }
    }

    /// Creates a `FixedProvider` with the default (allocated) version of the data struct.
    pub fn new_default() -> Self
    where
        M::DataStruct: Default,
    {
        Self::from_owned(M::DataStruct::default())
    }
}

impl<M> DataProvider<M> for FixedProvider<M>
where
    M: DataMarker,
    for<'a> <M::DataStruct as Yokeable<'a>>::Output: Clone,
{
    fn load(&self, _: DataRequest) -> Result<DataResponse<M>, DataError> {
        Ok(DataResponse {
            metadata: Default::default(),
            payload: self.data.clone(),
        })
    }
}

impl<M> fmt::Debug for FixedProvider<M>
where
    M: DynamicDataMarker,
    M: DataMarker,
    for<'a> &'a <M::DataStruct as Yokeable<'a>>::Output: fmt::Debug,
{
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.data.fmt(f)
    }
}

Messung V0.5 in Prozent
C=98 H=96 G=96

¤ Dauer der Verarbeitung: 0.4 Sekunden  ¤

*© 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.