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>
impl<M: DataMarker> FixedProvider<M>
sourcepub fn from_owned(data: M::DataStruct) -> Self
pub fn from_owned(data: M::DataStruct) -> Self
Creates a FixedProvider
with an owned (allocated) payload of the given data.
sourcepub fn from_static(data: &'static M::DataStruct) -> Self
pub fn from_static(data: &'static M::DataStruct) -> Self
Creates a FixedProvider
with a statically borrowed payload of the given data.
sourcepub fn from_payload(data: DataPayload<M>) -> Self
pub fn from_payload(data: DataPayload<M>) -> Self
Creates a FixedProvider
from an existing [DataPayload
].
sourcepub fn new_default() -> Selfwhere
M::DataStruct: Default,
pub fn new_default() -> Selfwhere
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,
impl<M: DataMarker> AnyProvider for FixedProvider<M>where
for<'a> YokeTraitHack<<M::DataStruct as Yokeable<'a>>::Output>: Clone,
M::DataStruct: MaybeSendSync,
source§impl<M> DataProvider<M> for FixedProvider<M>where
M: DataMarker,
for<'a> YokeTraitHack<<M::DataStruct as Yokeable<'a>>::Output>: Clone,
impl<M> DataProvider<M> for FixedProvider<M>where
M: DataMarker,
for<'a> YokeTraitHack<<M::DataStruct as Yokeable<'a>>::Output>: Clone,
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>
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§
§impl<P> AsDowncastingAnyProvider for Pwhere
P: AnyProvider + ?Sized,
impl<P> AsDowncastingAnyProvider for Pwhere
P: AnyProvider + ?Sized,
§fn as_downcasting(&self) -> DowncastingAnyProvider<'_, P>
fn as_downcasting(&self) -> DowncastingAnyProvider<'_, P>
Returns an object implementing
DynamicDataProvider<M>
when called on AnyProvider
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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