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

pub trait ErasedDataStruct: 'static {
    fn clone_into_box(&self) -> Box<dyn ErasedDataStruct>;
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

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

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

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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

Implementors