pub struct AnyPayloadProvider { /* private fields */ }Expand description
A data provider that returns clones of a fixed type-erased payload.
AnyPayloadProvider 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::any_payload::AnyPayloadProvider;
use std::borrow::Cow;
use writeable::assert_writeable_eq;
let provider =
AnyPayloadProvider::from_static::<HelloWorldV1Marker>(&HelloWorldV1 {
message: Cow::Borrowed("custom hello world"),
});
// Check that it works:
let formatter = HelloWorldFormatter::try_new_with_any_provider(
&provider,
&Default::default(),
)
.expect("key matches");
assert_writeable_eq!(formatter.format(), "custom hello world");
// Requests for invalid keys get MissingDataKey
assert!(matches!(
provider.load_any(icu_provider::data_key!("foo@1"), Default::default()),
Err(DataError {
kind: DataErrorKind::MissingDataKey,
..
})
))Implementations§
Source§impl AnyPayloadProvider
impl AnyPayloadProvider
Sourcepub fn from_owned<M: KeyedDataMarker>(data: M::Yokeable) -> Selfwhere
M::Yokeable: MaybeSendSync,
pub fn from_owned<M: KeyedDataMarker>(data: M::Yokeable) -> Selfwhere
M::Yokeable: MaybeSendSync,
Creates an AnyPayloadProvider with an owned (allocated) payload of the given data.
Sourcepub fn from_static<M: KeyedDataMarker>(data: &'static M::Yokeable) -> Self
pub fn from_static<M: KeyedDataMarker>(data: &'static M::Yokeable) -> Self
Creates an AnyPayloadProvider with a statically borrowed payload of the given data.
Sourcepub fn from_payload<M: KeyedDataMarker>(payload: DataPayload<M>) -> Selfwhere
M::Yokeable: MaybeSendSync,
pub fn from_payload<M: KeyedDataMarker>(payload: DataPayload<M>) -> Selfwhere
M::Yokeable: MaybeSendSync,
Creates an AnyPayloadProvider from an existing DataPayload.
Sourcepub fn from_any_payload<M: KeyedDataMarker>(payload: AnyPayload) -> Self
pub fn from_any_payload<M: KeyedDataMarker>(payload: AnyPayload) -> Self
Creates an AnyPayloadProvider from an existing AnyPayload.
Sourcepub fn new_default<M: KeyedDataMarker>() -> Self
pub fn new_default<M: KeyedDataMarker>() -> Self
Creates an AnyPayloadProvider with the default (allocated) version of the data struct.
Trait Implementations§
Source§impl AnyProvider for AnyPayloadProvider
impl AnyProvider for AnyPayloadProvider
Source§fn load_any(
&self,
key: DataKey,
_: DataRequest<'_>,
) -> Result<AnyResponse, DataError>
fn load_any( &self, key: DataKey, _: DataRequest<'_>, ) -> Result<AnyResponse, DataError>
AnyPayload according to the key and request.Source§impl<M> DataProvider<M> for AnyPayloadProviderwhere
M: KeyedDataMarker,
for<'a> YokeTraitHack<<M::Yokeable as Yokeable<'a>>::Output>: Clone,
M::Yokeable: ZeroFrom<'static, M::Yokeable> + MaybeSendSync,
impl<M> DataProvider<M> for AnyPayloadProviderwhere
M: KeyedDataMarker,
for<'a> YokeTraitHack<<M::Yokeable as Yokeable<'a>>::Output>: Clone,
M::Yokeable: ZeroFrom<'static, M::Yokeable> + MaybeSendSync,
Source§fn load(&self, req: DataRequest<'_>) -> Result<DataResponse<M>, DataError>
fn load(&self, req: DataRequest<'_>) -> Result<DataResponse<M>, DataError>
Auto Trait Implementations§
impl Freeze for AnyPayloadProvider
impl !RefUnwindSafe for AnyPayloadProvider
impl !Send for AnyPayloadProvider
impl !Sync for AnyPayloadProvider
impl Unpin for AnyPayloadProvider
impl !UnwindSafe for AnyPayloadProvider
Blanket Implementations§
Source§impl<P> AsDowncastingAnyProvider for Pwhere
P: AnyProvider + ?Sized,
impl<P> AsDowncastingAnyProvider for Pwhere
P: AnyProvider + ?Sized,
Source§fn as_downcasting(&self) -> DowncastingAnyProvider<'_, P>
fn as_downcasting(&self) -> DowncastingAnyProvider<'_, P>
DynamicDataProvider<M> when called on AnyProviderSource§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
Source§impl<T> Filterable for T
impl<T> Filterable for T
Source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> MaybeSendSync for T
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 72 bytes