Don't skip Option for nullable collections#1622
Don't skip Option for nullable collections#1622fengalin wants to merge 4 commits intogtk-rs:mainfrom
Option for nullable collections#1622Conversation
I think this also involves untangling our existing implementations a bit as they currently map |
sdroege
left a comment
There was a problem hiding this comment.
This looks too easy, I didn't expect that :)
|
There's also #1551 doing more or less the same (but a bit more?). I think the main problem here now is fixing |
|
@fengalin What's the plan to continue here, especially with the translation traits? |
|
My plan was to start over from the PR you linked and implement the changes in the glib bindings. But I got involved with other stuffs. I'll try to resume this later this week. |
|
Status on this:
Quoting the last commit:
Sample regen results (no update for GStreamer):
The outcome is that pub fn content_type_guess(
filename: Option<impl AsRef<std::path::Path>>,
data: Option<&[u8]>,
) -> (glib::GString, bool) { .. }
Because similar annotations don't necessarily mean that the argument can be an pub fn set_dash(&self, dash: Option<&[f32]>) { .. }We could think passing Another example is pub fn new(mime_types: Option<&[&str]>) -> ContentFormats { .. }The doc doesn't say anything about a difference between an empty array and an undefined argument. See the Another approach could be to not generate the |
src/parser.rs
Outdated
| const EMPTY_CTYPE: &str = "/*EMPTY*/"; | ||
|
|
||
| #[derive(Debug, Default)] | ||
| struct ParsedType { |
There was a problem hiding this comment.
The naming here confused me a bit, could use a small comment on what it is.
|
@bilelmoussaoui: when you get a chance, I'd be interested by your opinion on the question in this comment #1622 (comment) |
I would generate the Option and let the user override if they want to disable that. As we to tend to trust the nullability annotations |
Option for nullable collectionsOption for nullable collections
|
can you open PRs for the changes for gtk4-rs/gtk-rs-core? i will review and merge this one afterwards. |
Co-authored-by: Andy Russell <arussell123@gmail.com> Fixes gtk-rs#1133
This simplifies constructions a bit.
9e6d075 to
8fd6a08
Compare
8fd6a08 to
d7398c7
Compare
f2665a6 to
1598d67
Compare
Nullable collection were represented as a `Vec<_>` or `[_]`, but an empty collection is not the same as an undefined collection. Don't do this for return and output values though: in practice the C implementations return NULL when the size is 0. So it doesn't make much sense using an `Option<_>` in that case. Finally, Gir now parses the `zero-terminated` annotation which allows detecting functions returning an array for which the length is not defined by a length argument. Those functions used to require an explicit `manual` declaration in the `Gir.toml` and are automatically commented out now. Fixes: gtk-rs#1133 See also: gtk-rs/gtk-rs-core#1257
1598d67 to
27b9ace
Compare
https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/561
|
Nullable collection were represented as a
Vec<_>or[_], but an empty collection is not the same as an undefined collection. Rust code can express this using anOption<_>.Don't do this for return and output values though: in practice the C implementations return NULL when the size is 0. So it doesn't make much sense using an
Option<_>in that case.Finally, Gir now parses the
zero-terminatedannotation which allows detecting functions returning an array for which the length is not defined by a length argument. Those functions used to require an explicitmanualdeclaration in theGir.tomland are automatically commented out now.Sample regen results (no changes for GStreamer):
gtk-rs-core: fengalin/gtk-rs-core@4f0786bgtk4-rs: fengalin/gtk4-rs@4bf3298Fixes: #1133
See also: gtk-rs/gtk-rs-core#1257