Created
November 22, 2022 22:42
-
-
Save TheButlah/9ad73f3c0c93059616e1f6962298b3e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Current flatbuffers version: v22.10.26 | |
Currently in rust, flatbuffers exposes two APIs for constructing a table: | |
```rust | |
let t1 = MyTable::create(&mut fbb, &MyTableArgs{ field1: None, field2: Some(10) }; | |
let t2 = MyTableBuilder::new(&mut fbb) | |
.add_field2(10) | |
.finish(); | |
``` | |
I personally always use the first approach, but one footgun with the first approach is that adding a new field to a flatbuffer is a breaking change. This is because a new pub field is added to `MyTableArgs`. | |
To safeguard my code against this, I always use `..Default::default()` as the last argument when constructing `MyTable`. But I warnings that this argument is unnecessary, because from rust's perspective all the arguments have already been supplied. | |
I think it would be a good idea to slap a #[non_exhaustive] on the `MyTableArgs` generated type, to *force* users to always provide a `...Default::default()`. Thoughts? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment