KEMBAR78
Simplify construction of `Ref` and `OutRef` directly by kennykerr · Pull Request #3730 · microsoft/windows-rs · GitHub
Skip to content

Conversation

@kennykerr
Copy link
Collaborator

@kennykerr kennykerr commented Aug 27, 2025

#3025 added the the Ref and OutRef types that represent borrowed types, providing the same memory layout but also offer lifetime management and conveniences to make dealing with in and out parameters safe and convenient:

unsafe extern "system" fn DllGetActivationFactory(
    name: Ref<HSTRING>,
    factory: OutRef<IActivationFactory>,
) -> HRESULT

This made it much simpler to implement ABIs like DllGetActivationFactory but didn't provide much in the way of calling functions with those same ABI types. The thinking was that these would typically be called from some other language like C++, which is typically the case.

In order to make it easier to define ABI boundaries directly in Rust that might be called from Rust itself, this update adds some conveniences to safely construct Ref and OutRef types from local Rust types again with the same memory layout and lifetime. This is mainly just adding more convenient From implementations for Ref and Default implementations for both. The tests illustrate how this might be used.

@kennykerr kennykerr changed the title ref caller Simplify constructing Ref and OutRef directly Aug 27, 2025
@kennykerr kennykerr changed the title Simplify constructing Ref and OutRef directly Simplify construction of Ref and OutRef directly Aug 27, 2025
@kennykerr
Copy link
Collaborator Author

Blocked on #3731

@kennykerr kennykerr merged commit df8a1e9 into master Aug 28, 2025
29 checks passed
@kennykerr kennykerr deleted the ref-from branch August 28, 2025 13:35
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