Comments (16)
I think I might be fine with postponing all kinds of clever processing, but it's still difficult to settle on a uniform solution.
Simply using &mut T
(Option<&mut T>
for optional
ones) doesn't work well for returning objects and boxed types (nothing to initialize the variable with at the call site). We could use &mut Option<T>
and Option<&mut Option<T>>
for that at a cost to ergonomics and wait for &out
to become available. This is something that will work in all cases (we'll still have to add temporary variables when conversions are needed).
We could just put the actual return type and all the outparams in a tuple and return that but what about the optional outparams?
from gir.
It might be solution.
Only it is not clear whether or not to restrict the typekinds of return values.
from gir.
There functions with mixed outparams (optional and not)?
Any way to detect when parameters optional (besides #119) ?
from gir.
By optional I mean optional="1"
, you are allowed to pass NULL
to ignore the value. Sometimes this has performance impact -- the function will take extra time to produce the value, but only if you actually want it. Can't find an example right now.
BTW optional seems to be the majority.
I don't know if there are combinations of optional and non-optional.
from gir.
In Gtk-3.0.gir no elements by XPath //parameter[@direction="out" and @optional="0"]
and many by //parameter[@direction="out" and not(@optional)]
Ex. gtk_accel_label_get_accel
, gtk_box_query_child_packing
, gtk_button_get_alignment
.
Main problem IMHO how to determine whether the client needs these values, or we can not ask them.
from gir.
At this point I could even settle for treating all of them as non-optional, to be fixed/optimized later. This will allow returning a tuple; if the function isn't void, making the return value the first element.
from gir.
Need to look out for nullability. Much the same as with actual return values, they aren't tagged as nullable reliably.
from gir.
Agree.
As for not (bool and ()) returning functions, I found 7 (by XPath //method[return-value[type[@name!="gboolean" and @name !="none"]] and parameters/parameter[@direction="out"]]
):
gtk_cell_area_get_cell_at_position -> CellRenderer,
gtk_icon_info_load_symbolic -> GdkPixbuf.Pixbuf,
gtk_icon_info_load_symbolic_finish -> GdkPixbuf.Pixbuf,
gtk_icon_info_load_symbolic_for_context -> GdkPixbuf.Pixbuf,
gtk_icon_info_load_symbolic_for_context_finish -> GdkPixbuf.Pixbuf,
gtk_icon_info_load_symbolic_for_style -> GdkPixbuf.Pixbuf,
gtk_tree_selection_get_selected_rows -> GLib.List
All this functions return objects, so it can be converted by XXX::From_glib_none.
from gir.
As result we have next "types" functions with out parameters by returning type:
- () => (current mode) converted to (outs),
- bool => converted to Option<(outs)>,
- others => converted to (ret, outs)
from gir.
IMHO this is different issue (it main focus function return type, not types of outs). I try to add it tomorrow with list of functions, and then start to fix it.
Or we can use current №119 and add new for other return types.
from gir.
bool => converted to Option(outs),
I have a feeling this will be wrong for some functions.
We could turn this one into an outparams meta-issue.
from gir.
() => (current mode) converted to (outs), bool => converted to Option(outs), others => converted to (ret, outs)
This looks good, we can weed out the exceptions later or just manually.
Oh, except if the function has an error
outparam, in which case it's Result<(outs)>
.
If the tuple has only one element it [the tuple] better be elided. ;)
from gir.
Returning errors can be mixed with out parameters (//method[@throws="1" and parameters/parameter[@direction="out"]]
=> 7 cases, //method[@throws="1" and not(parameters/parameter[@direction="out"])]
=> 42) and make 4th case which fully non covered.
For 7 cases:
gtk_builder_value_from_string
and gtk_builder_value_from_string_type
returns bool with out GValue,
5 returns GdkPixbuf.Pixbuf
(#117 (comment)),
and last gtk_icon_info_load_symbolic_for_style
also return GdkPixbuf.Pixbuf
and deprecated in 3.0.
IMHO better first comment all functions with throw and on next stage focus on non out throws.
from gir.
As for elide tupple: it already done https://github.com/gkoz/gir/blob/master/src/codegen/function_body.rs#L80
from gir.
Yes, throws
is a separate topic but just in case
returns
bool
If the function throws
we should treat the bool
return type as if it's void
.
As for elide tupple: it already done
Cool :)
from gir.
@gkoz, I plan add new Issue about "Object returning functions with outs" same as I do in №130 and close this issue.
from gir.
Related Issues (20)
- Signal handler (and other closures) return values don't use `IntoGlibPtr` trait
- Don't create `assert_initialized_main_thread!()` assertions for enum/flags methods HOT 1
- Can't autogenerate `g_file_copy()` and others with latest gir files anymore HOT 1
- Make shared library error message helpful
- generated code broken HOT 2
- Regression in soup3-rs
- Types' names that start with a number in input gir file produce invalid code
- [Feature request] Create release for 0.16 HOT 1
- [Feature request] Create release for 0.17 HOT 1
- Fails to find .gir files out of nowhere
- Suggestion: Remove dox feature in favor of rustc args HOT 6
- How to fix libgir::parser warning with GTK4? HOT 4
- No bindings generated for Vala async methods
- `void`-returning non-throwing async method generates broken binding code HOT 1
- DEFAULT_GIR_PATH could respect CARGO_TARGET_DIR
- Append implementors list to ExtManual traits
- Add a way to disable abi test for a certain type
- Question: How to rename Object HOT 4
- Should generate deprecate warning in rust code, when C code macro expand to `__attribute__` `__deprecated__` HOT 6
- Should not implement `Default` if there is a function called `default`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gir.