Trait icu_provider::dynutil::UpcastDataPayload

source ·
pub trait UpcastDataPayload<M>
where M: DataMarker, Self: Sized + DataMarker,
{ // 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§