AnyPayloadProvider

Struct AnyPayloadProvider 

Source
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

Source

pub fn from_owned<M: KeyedDataMarker>(data: M::Yokeable) -> Self

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

Source

pub fn from_static<M: KeyedDataMarker>(data: &'static M::Yokeable) -> Self

Creates an AnyPayloadProvider with a statically borrowed payload of the given data.

Source

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

Creates an AnyPayloadProvider from an existing DataPayload.

Source

pub fn from_any_payload<M: KeyedDataMarker>(payload: AnyPayload) -> Self

Creates an AnyPayloadProvider from an existing AnyPayload.

Source

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

Source§

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

Loads an AnyPayload according to the key and request.
Source§

impl<M> DataProvider<M> for AnyPayloadProvider
where 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>

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

impl Debug for AnyPayloadProvider

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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

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

Source§

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> Filterable for T

Source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. 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, 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.
Source§

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

Source§

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