-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. This commit also moved the `Bound::alias` field to the elligible `BoundType` variants and `BoundType` variants contain named fields instead of a tuple of value: * Only certain `BoundType`s actually used an alias. * This make it clear whether the `char` refers to a lifetime or an alias.
- Loading branch information
Showing
16 changed files
with
499 additions
and
301 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use crate::analysis::bounds::Bounds; | ||
|
||
impl Bounds { | ||
pub fn to_generic_params_str(&self) -> String { | ||
self.to_generic_params_str_(false) | ||
} | ||
|
||
pub fn to_generic_params_str_async(&self) -> String { | ||
self.to_generic_params_str_(true) | ||
} | ||
|
||
fn to_generic_params_str_(&self, r#async: bool) -> String { | ||
let mut res = String::new(); | ||
|
||
if self.lifetimes.is_empty() && self.used.iter().find_map(|b| b.alias()).is_none() { | ||
return res; | ||
} | ||
|
||
res.push('<'); | ||
let mut is_first = true; | ||
|
||
for lt in self.lifetimes.iter() { | ||
if is_first { | ||
is_first = false; | ||
} else { | ||
res.push_str(", "); | ||
} | ||
res.push('\''); | ||
res.push(*lt); | ||
} | ||
|
||
for bound in self.used.iter() { | ||
if let Some(type_param_def) = bound.type_parameter_definition(r#async) { | ||
if is_first { | ||
is_first = false; | ||
} else { | ||
res.push_str(", "); | ||
} | ||
res.push_str(&type_param_def); | ||
} | ||
} | ||
res.push('>'); | ||
|
||
res | ||
} | ||
} |
Oops, something went wrong.