KEMBAR78
Use `Ref` for generic type parameters by kennykerr · Pull Request #3435 · microsoft/windows-rs · GitHub
Skip to content

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