Trait icu_provider::dynutil::UpcastDataPayload

source ·
pub trait UpcastDataPayload<M>{
    // Required method
    fn upcast(other: DataPayload<M>) -> DataPayload<Self>;
}
Expand description

Trait to allow conversion from DataPayload<T> to DataPayload<S>.

This trait can be manually implemented in order to enable impl_dynamic_data_provider.

Required Methods§

source

fn upcast(other: DataPayload<M>) -> DataPayload<Self>

Upcast a DataPayload<T> to a DataPayload<S> where T implements trait S.

§Examples

Upcast and then downcast a data struct of type Cow<str> (cart type String) via AnyPayload:

use icu_provider::dynutil::UpcastDataPayload;
use icu_provider::hello_world::*;
use icu_provider::prelude::*;
use std::borrow::Cow;

let original = DataPayload::<HelloWorldV1Marker>::from_static_str("foo");
let upcasted = AnyMarker::upcast(original);
let downcasted = upcasted
    .downcast::<HelloWorldV1Marker>()
    .expect("Type conversion");
assert_eq!(downcasted.get().message, "foo");

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<M> UpcastDataPayload<M> for AnyMarker

source§

impl<M> UpcastDataPayload<M> for ExportMarker
where M: DynamicDataMarker, M::DataStruct: Sync + Send, for<'a> <M::DataStruct as Yokeable<'a>>::Output: Bake + BakeSize + Serialize, for<'a> YokeTraitHack<<M::DataStruct as Yokeable<'a>>::Output>: PartialEq,