gtk-rs / gir

Tool to generate rust bindings and user API for glib-based libraries
https://gtk-rs.org/gir/book/
MIT License
236 stars 107 forks source link

Figure out a replacement of AsRef<T> for fundamental types #1414

Open bilelmoussaoui opened 1 year ago

bilelmoussaoui commented 1 year ago

Currently gir, would generate AsRef<T> for fundamental types as a replacement of IsA<T> that is used for objects/interfaces. The problem with using AsRef<T> is it causes problems when the param is passed by value instead of by reference, so having a still generic Option<impl AsRef<T>> would mean having to clone the param before calling into_glib_ptr()

That is sub-optimal and we should probably avoid using AsRef here; maybe an alternative would be to allow configuring a trait to be used for a fundamental type and it sub-types. For example fundamental_trait = "IsExpression or something like that.

Needs more thinking though. Details can be found at https://github.com/gtk-rs/gir/pull/1413/files#r1044662046