Attribute Macro icu_provider::data_struct
#[data_struct]
Expand description
The #[data_struct]
attribute should be applied to all types intended
for use in a DataStruct
.
It does the following things:
Apply #[derive(Yokeable, ZeroFrom)]
. TheZeroFrom
derive can be customized with#[zerofrom(clone)]
on non-ZeroFrom fields.
In addition, the attribute can be used to implement DynamicDataMarker
and/or DataMarker
by adding symbols with optional marker path strings:
use icu::locale::fallback::*;
use icu_provider::prelude::*;
use std::borrow::Cow;
#[icu_provider::data_struct(
FooV1Marker,
BarV1Marker = "demo/bar@1",
marker(
BazV1Marker,
"demo/baz@1",
fallback_by = "region",
)
)]
pub struct FooV1<'data> {
message: Cow<'data, str>,
};
// Note: FooV1Marker implements `DynamicDataMarker` but not `DataMarker`.
// The other two implement `DataMarker`.
assert_eq!(BarV1Marker::INFO.path.as_str(), "demo/bar@1");
assert_eq!(
BarV1Marker::INFO.fallback_config.priority,
LocaleFallbackPriority::Language
);
assert_eq!(BazV1Marker::INFO.path.as_str(), "demo/baz@1");
assert_eq!(
BazV1Marker::INFO.fallback_config.priority,
LocaleFallbackPriority::Region
);