Trait icu_provider::erased::ErasedDataStruct[][src]

pub trait ErasedDataStruct: 'static {
    fn into_any(self: Box<Self>) -> Box<dyn Any>;
fn into_any_rc(self: Rc<Self>) -> Rc<dyn Any>;
fn as_any(&self) -> &dyn Any; }
Expand description

Auto-implemented trait allowing for type erasure of data provider structs.

Requires the static lifetime in order to be convertible to Any.

Required methods

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

Examples
use icu_provider::erased::ErasedDataStruct;
use icu_provider::hello_world::HelloWorldV1;

// Create type-erased box
let erased: Box<dyn ErasedDataStruct> = Box::new(HelloWorldV1::default());

// Convert to typed box
let boxed: Box<HelloWorldV1> = erased.into_any().downcast().expect("Types should match");

Return this trait object reference as &dyn Any.

Also see associated method downcast_ref().

Examples
use icu_provider::erased::ErasedDataStruct;
use icu_provider::hello_world::HelloWorldV1;

// Create type-erased reference
let data = HelloWorldV1::default();
let erased: &dyn ErasedDataStruct = &data;

// Borrow as typed reference
let borrowed: &HelloWorldV1 = erased.as_any().downcast_ref().expect("Types should match");

Trait Implementations

Clone the cart C into a Yokeable struct, which may retain references into C.

Implementors