Trait icu_provider::any::AnyProvider
source · pub trait AnyProvider {
// Required method
fn load_any(
&self,
marker: DataMarkerInfo,
req: DataRequest<'_>,
) -> Result<AnyResponse, DataError>;
}
Expand description
An object-safe data provider that returns data structs cast to dyn Any
trait objects.
§Examples
use icu_locale_core::langid;
use icu_provider::hello_world::*;
use icu_provider::prelude::*;
use std::borrow::Cow;
let any_provider = HelloWorldProvider.as_any_provider();
// Downcasting manually
assert_eq!(
any_provider
.load_any(
HelloWorldV1Marker::INFO,
DataRequest {
id: DataIdentifierBorrowed::for_locale(
&langid!("de").into()
),
..Default::default()
}
)
.expect("load should succeed")
.downcast::<HelloWorldV1Marker>()
.expect("types should match")
.payload
.get(),
&HelloWorldV1 {
message: Cow::Borrowed("Hallo Welt"),
},
);
// Downcasting automatically
let downcasting_provider: &dyn DataProvider<HelloWorldV1Marker> =
&any_provider.as_downcasting();
assert_eq!(
downcasting_provider
.load(DataRequest {
id: DataIdentifierBorrowed::for_locale(&langid!("de").into()),
..Default::default()
})
.expect("load should succeed")
.payload
.get(),
&HelloWorldV1 {
message: Cow::Borrowed("Hallo Welt"),
},
);
Required Methods§
sourcefn load_any(
&self,
marker: DataMarkerInfo,
req: DataRequest<'_>,
) -> Result<AnyResponse, DataError>
fn load_any( &self, marker: DataMarkerInfo, req: DataRequest<'_>, ) -> Result<AnyResponse, DataError>
Loads an AnyPayload
according to the marker and request.