PSA: FIDL Rust tables now implement Default

6 views
Skip to first unread message

Mitchell Kember

unread,
Apr 25, 2023, 5:32:13 PM4/25/23
to fidl-dev, rust-...@fuchsia.dev
You can stop reading if you don't use the FIDL Rust bindings.

As of fxr/844716, FIDL tables implement the Default trait. Instead of constructing tables like this:

// "Struct update" style
let my_table = MyTable {
    foo: Some(42),
    ..MyTable::EMPTY
};
// Assignment style
let my_table = MyTable::EMPTY;
my_table.foo = Some(42);

You should now construct them like this:

// "Struct update" style
let my_table = MyTable {
    foo: Some(42),
    ..Default::default()
};
// Assignment style
let my_table = MyTable::default();
my_table.foo = Some(42);

I will migrate all existing code and remove the EMPTY constant when I'm done.

See fxb/102876 if you're curious for more details.


Mitchell

..
Reply all
Reply to author
Forward
0 new messages