Struct icu_provider::struct_provider::StructProvider[][src]

pub struct StructProvider<'data, M> where
    M: DataMarker<'data>, 
{ pub key: ResourceKey, pub data: DataPayload<'data, M>, }
Expand description

A data provider that returns clones of a constant data payload.

Examples

use icu_provider::prelude::*;
use icu_provider::hello_world::*;
use icu_provider::struct_provider::StructProvider;
use std::borrow::Cow;

let local_data = HelloWorldV1 {
    message: Cow::Owned("hello world".to_string()),
};

// A placeholder key to use to serve the data struct
const SAMPLE_KEY: ResourceKey = icu_provider::resource_key!(x, "xyz", "example", 1);

let provider = StructProvider {
    key: SAMPLE_KEY,
    data: DataPayload::from_owned(local_data),
};

let payload: DataPayload<HelloWorldV1Marker> = provider.load_payload(&DataRequest::from(SAMPLE_KEY))
    .expect("Load should succeed")
    .take_payload()
    .expect("Data should be present");

assert_eq!(payload.get().message, "hello world");

Fields

key: ResourceKeydata: DataPayload<'data, M>

Trait Implementations

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Clone this trait object reference, returning a boxed trait object.

Return this boxed trait object as Box<dyn Any>. Read more

Return this trait object reference as &dyn Any. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.