Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

PSA: FIDL Rust tables now implement Default

11 views
Skip to first unread message

Mitchell Kember

unread,
Apr 26, 2023, 1:36:30 AM4/26/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