- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 114
          Use impl Trait instead of generic type names with trait bound
          #1153
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| So this is far less trivial than anticipated, and not how I planned to spend my sunday! There's still some trouble with trampolines now that I made aliases optional but  the  Other than that the current "heuristic" to detect whether to use  I'll be out for a while, but feel more than welcome to go over the  | 
| // TODO: This is just a heuristic for now, based on what we do in codegen! | ||
| // Theoretically the surrounding function should determine whether it needs to | ||
| // reuse an alias (ie. to use in `call_func::<P, Q, R>`) or not. | ||
| // In the latter case an `impl` is generated instead of a type name/alias. | ||
| pub fn has_alias(&self) -> bool { | ||
| matches!(*self, Self::NoWrapper) | ||
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyone have a suggestion how to determine this?
| pub alias: char, | ||
| /// Bound does not have an alias when `param: impl type_str` is used | ||
| pub alias: Option<char>, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What this change is all about :)
| .filter(|bound| skip.contains(&bound.alias)) | ||
| // TODO: False or true? | ||
| .filter(|bound| bound.alias.map_or(false, |alias| skip.contains(&alias))) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: Try and remember what was up here.
| let bounds = bounds.iter().filter(|bound| { | ||
| bound.alias.map_or(true, |alias| !skip.contains(&alias)) | ||
| && (!filter_callback_modified || !bound.callback_modified) | ||
| }); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to revisit this: can't be a trait bound if it doesn't have an alias, then it's only written in-place with impl.
| // TODO: enforce that this is only used on NoWrapper! | ||
| // TODO: Analyze if alias is used in function, otherwise set to None! | ||
| .chain(bounds.filter_map(|b| b.alias).map(|a| a.to_string())) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ambiguity between NoWrapper and impl (no alias) again.
`impl` is quite a bit more concise and readable when a type parameter with trait bound is only used once. Aside that, this simplifies some of the type handling in trampolines by using `P: IsA<>` directly instead of through a `where P: ...` indirection.
| @GuillaumeGomez Should we get this in now then? | 
| This is good enough for now. Thanks @MarijnS95 ! | 
| @MarijnS95 You update your gtk-rs-core/gtk3-rs/gtk4-rs/gstreamer-rs PRs? :) | 
| @sdroege Updated everything  | 
For gtk-rs/gtk-rs-core#89 (comment)
implis quite a bit more concise and readable when a type parameter with trait bound is only used once. Aside that, this simplifies some of the type handling in trampolines by usingP: IsA<>directly instead of through awhere P: ...indirection.Related MRs:
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/778
gtk-rs/gtk-rs-core#95
gtk-rs/gtk3-rs#547
gtk-rs/gtk4-rs#404