fable_lib

Macro fable

Source
macro_rules! fable {
    ($fidl_type:path { $($rest:tt)* }) => { ... };
    (@internal $table:ident $field:ident : $value:expr, $($rest:tt)*) => { ... };
    (@internal $table:ident $field:ident, $($rest:tt)*) => { ... };
    (@internal $table:ident) => { ... };
}
Expand description

Shorthand for creating a FIDL table in a way that will not cause build breakages if new fields are added to the table in the future.

  • The values do not have to be wrapped in Some; this is inferred automatically.
  • Empty fields can either be omitted or explicitly set to None.
  • When a field name matches the name of an in-scope variable or parameter, a shorthand notation is available (just like in Rust struct initializers).

Example:

use fidl_fuchsia_intl::{CalendarId, LocaleId, Profile, TemperatureUnit};

let calendars = vec![CalendarId { id: "gregorian".to_string() }];
let time_zones = None;

let table = fable! {
  Profile {
    locales: Some(vec![LocaleId { id: "en-US".to_string() }]),
    // `Some` can be omitted
    temperature_unit: TemperatureUnit::Fahrenheit,
    // Shorthand notation when the field and variable names match
    calendars,
    time_zones,
  }
};