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

Calculate type signatures at compile time #2729

Merged
merged 5 commits into from
Dec 7, 2023
Merged

Calculate type signatures at compile time #2729

merged 5 commits into from
Dec 7, 2023

Conversation

kennykerr
Copy link
Collaborator

WinRT use type signatures to generate GUIDs for generic interfaces. This update provides a const implementation for class and interface signatures, much like C++/WinRT, so that these signatures don't need to be redundantly included in the generated bindings as they can be derived from the other trait metadata included in the Rust bindings. This also helps to make the generated code more readable and concise.

For example, this generated trait:

impl ::windows_core::RuntimeType for TensorFloat {
    const SIGNATURE: ::windows_core::imp::ConstBuffer = ::windows_core::imp::ConstBuffer::from_slice(b"rc(Windows.AI.MachineLearning.TensorFloat;{f2282d82-aa02-42c8-a0c8-df1efc9676e1})");
}

Is simplified to this:

impl ::windows_core::RuntimeType for TensorFloat {
    const SIGNATURE: ::windows_core::imp::ConstBuffer = ::windows_core::imp::ConstBuffer::for_class::<Self>();
}

@kennykerr
Copy link
Collaborator Author

Trait bounds on const functions need Rust 1.62 or later: #2730

@kennykerr kennykerr reopened this Dec 7, 2023
@kennykerr kennykerr merged commit 8e71051 into master Dec 7, 2023
47 checks passed
@kennykerr kennykerr deleted the signatures branch December 7, 2023 18:47
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