Trait DynamicDataMarker

Source
pub trait DynamicDataMarker: 'static {
    type DataStruct: for<'a> Yokeable<'a>;
}
Expand description

Trait marker for data structs. All types delivered by the data provider must be associated with something implementing this trait.

Data markers normally generated with the data_marker macro.

Also see DataMarker.

Note: DynamicDataMarkers are quasi-const-generic compile-time objects, and as such are expected to be unit structs. As this is not something that can be enforced by the type system, we currently only have a 'static bound on them (which is needed by a lot of our code).

§Examples

Manually implementing DynamicDataMarker for a custom type:

use icu_provider::prelude::*;
use std::borrow::Cow;

#[derive(yoke::Yokeable, zerofrom::ZeroFrom)]
struct MyDataStruct<'data> {
    message: Cow<'data, str>,
}

struct MyDataStructMarker;

impl DynamicDataMarker for MyDataStructMarker {
    type DataStruct = MyDataStruct<'static>;
}

// We can now use MyDataStruct with DataProvider:
let s = MyDataStruct {
    message: Cow::Owned("Hello World".into()),
};
let payload = DataPayload::<MyDataStructMarker>::from_owned(s);
assert_eq!(payload.get().message, "Hello World");

Required Associated Types§

Source

type DataStruct: for<'a> Yokeable<'a>

A type that implements Yokeable. This should typically be the 'static version of a data struct.

Implementors§

Source§

impl DynamicDataMarker for BufferMarker

Source§

type DataStruct = &'static [u8]

Source§

impl<DataStruct: for<'a> Yokeable<'a>> DynamicDataMarker for ErasedMarker<DataStruct>

Source§

type DataStruct = DataStruct

Source§

impl<Y> DynamicDataMarker for NeverMarker<Y>
where for<'a> Y: Yokeable<'a>,