Skip to content
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

Use Ref for generic type parameters #3435

Merged
merged 2 commits into from
Jan 13, 2025
Merged

Use Ref for generic type parameters #3435

merged 2 commits into from
Jan 13, 2025

Conversation

kennykerr
Copy link
Collaborator

@kennykerr kennykerr commented Jan 13, 2025

Now that Ref no longer requires a lifetime parameter #3433 we can use it in a trait as a type alias and generalize the concept of a reference or input parameter for generic WinRT types. This solves a longstanding problem with generic type parameters where they were generated as references "just in case" since there was no way to know whether it would be specialized with a copyable or non-copyable type.

So now whether you're implementing specializations of IVector<T> or writing a closure for TypedEventHandler<Sender, Result>, you can directly use the generic type arguments without having to indirect through a reference. For generic implementations - implementations that have to deal with any kind of T - you can use the Type::deref helper to convert a T::Ref into a &T::Default for efficient but generic handling of type parameters.

This also gets us closer to resolving #3233 and #1339.

@kennykerr kennykerr merged commit 87f268a into master Jan 13, 2025
75 checks passed
@kennykerr kennykerr deleted the generic-ref branch January 13, 2025 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant