macro_rules! define_preferences {
    (
        $(#[$doc:meta])*
        $([$derive_attrs:ty])?
        $name:ident,
        {
            $(
                $(#[$key_doc:meta])*
                $key:ident: $pref:ty
            ),*
        }
     ) => { ... };
}
Expand description

A macro to facilitate generation of preferences struct.

The generated preferences struct provides methods for merging and converting between Locale and the preference bag. See preferences for use cases.

In the example below, the input argument is the generated preferences struct which can be auto-converted from a Locale, or combined from a Locale and Preferences Bag.

§Examples

use icu::locale::{
    preferences::{
        define_preferences,
        extensions::unicode::keywords::HourCycle
    },
    locale,
};

define_preferences!(
    [Copy]
    TimeFormatterPreferences,
    {
        hour_cycle: HourCycle
    }
);

struct TimeFormatter {}

impl TimeFormatter {
    pub fn try_new(prefs: TimeFormatterPreferences) -> Result<Self, ()> {
        // load data and set struct fields based on the prefs input
        Ok(Self {})
    }
}

let loc = locale!("en-US");

let tf = TimeFormatter::try_new(loc.into());