Struct icu_provider_adapters::fixed::FixedProvider

source ·
pub struct FixedProvider<M: DataMarker> { /* private fields */ }
Expand description

A data provider that returns clones of a fixed type-erased payload.

FixedProvider implements [AnyProvider], so it can be used in *_with_any_provider constructors across ICU4X.

§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::<HelloWorldV1Marker>::from_static(&HelloWorldV1 {
        message: Cow::Borrowed("custom hello world"),
    });

// Check that it works:
let formatter = HelloWorldFormatter::try_new_with_any_provider(
    &provider,
    Default::default(),
)
.expect("marker matches");
assert_writeable_eq!(formatter.format(), "custom hello world");

// Requests for invalid markers get MissingDataMarker
assert!(matches!(
    provider.load_any(DummyMarker::INFO, Default::default()),
    Err(DataError {
        kind: DataErrorKind::MarkerNotFound,
        ..
    })
))

Implementations§

source§

impl<M: DataMarker> FixedProvider<M>

source

pub fn from_owned(data: M::DataStruct) -> Self

Creates a FixedProvider with an owned (allocated) payload of the given data.

source

pub fn from_static(data: &'static M::DataStruct) -> Self

Creates a FixedProvider with a statically borrowed payload of the given data.

source

pub fn from_payload(data: DataPayload<M>) -> Self

Creates a FixedProvider from an existing [DataPayload].

source

pub fn new_default() -> Self
where M::DataStruct: Default,

Creates a FixedProvider with the default (allocated) version of the data struct.

Trait Implementations§

source§

impl<M: DataMarker> AnyProvider for FixedProvider<M>
where for<'a> YokeTraitHack<<M::DataStruct as Yokeable<'a>>::Output>: Clone, M::DataStruct: MaybeSendSync,

source§

fn load_any( &self, marker: DataMarkerInfo, _: DataRequest<'_>, ) -> Result<AnyResponse, DataError>

Loads an [AnyPayload] according to the marker and request.
source§

impl<M> DataProvider<M> for FixedProvider<M>
where M: DataMarker, for<'a> YokeTraitHack<<M::DataStruct as Yokeable<'a>>::Output>: Clone,

source§

fn load(&self, _: DataRequest<'_>) -> Result<DataResponse<M>, DataError>

Query the provider for data, returning the result. Read more
source§

impl<M> Debug for FixedProvider<M>
where M: DynamicDataMarker + DataMarker, for<'a> &'a <M::DataStruct as Yokeable<'a>>::Output: Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<M> Freeze for FixedProvider<M>
where <M as DynamicDataMarker>::DataStruct: Freeze,

§

impl<M> RefUnwindSafe for FixedProvider<M>
where <M as DynamicDataMarker>::DataStruct: RefUnwindSafe,

§

impl<M> Send for FixedProvider<M>
where <M as DynamicDataMarker>::DataStruct: Sync + Send,

§

impl<M> Sync for FixedProvider<M>
where <M as DynamicDataMarker>::DataStruct: Sync,

§

impl<M> Unpin for FixedProvider<M>
where <M as DynamicDataMarker>::DataStruct: Unpin,

§

impl<M> UnwindSafe for FixedProvider<M>
where <M as DynamicDataMarker>::DataStruct: RefUnwindSafe + UnwindSafe,

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
§

impl<P> AsDowncastingAnyProvider for P
where P: AnyProvider + ?Sized,

§

fn as_downcasting(&self) -> DowncastingAnyProvider<'_, P>

Returns an object implementing DynamicDataProvider<M> when called on AnyProvider
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

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

source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,