You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generate Into<Option<_>> in argument position where applicable
This commit adds support for generating `Into<Option<_>>`, `Into<Option<&_>>`
and `Into<Option<&IsA<_>>` in argument position. The existing `analysis::Bound`
type was updated to support new bounds for these variants:
1. Owned value
This is straightforward, just need a `to_glib_extra` `.into()`:
```rust
impl AudioDecoder {
fn finish_frame(&self, buf: impl Into<Option<gst::Buffer>>) -> Result<...> {
[...]
ffi::gst_audio_decoder_finish_frame(
[...]
buf.into().into_glib_ptr(),
)
[...]
}
}
```
2. Concrete types by reference
Same, but needs a lifetime:
```rust
impl TextOverlay {
fn set_text<'a>(&self, text: impl Into<Option<&'a str>>) {
[...]
ffi::ges_text_overlay_set_text()
[...]
text.into().to_glib_none().0,
))
[...]
}
}
```
3. Trait bound by reference
Needs a lifetime and a generic parameter and a longer `to_glib_extra`:
```rust
impl Pipeline {
fn use_clock<'a, P: IsA<Clock>>(&self, clock: impl Into<Option<&'a P>>) {
[...]
ffi::gst_pipeline_use_clock(
[...]
clock.into().as_ref().map(|p| p.as_ref()).to_glib_none().0,
))
[...]
}
}
```
Other Changes:
These changes revealed a bug in trampoline `user_data` generic parameters
handling: these parameters can be grouped, in which case the grouped callbacks
are passed as a tuple in `user_data`. The actual callback types are then
required to recover the callbacks from the tuple. The way it was implemented,
all the callback generic parameters (bounds) from the outter function were
considered as taking part in the `user_data`, regardless of the actual grouping.
From the code bases on which I tested this, this had no consequences since
callbacks for a particular function were all grouped anyway. However, with the
new bounds implemented by this commit, functions with callbacks can now use a
lifetime, which may not be part of the callback signatures, in which case it
should not be included as part of a callback group. This is now fixed. I took
the liberty to add details and remane a couple of identifiers to ease my
understanding of what this code was achieving.
0 commit comments