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

Add JSON validator sample for WinRT #2824

Merged
merged 2 commits into from
Jan 31, 2024
Merged

Add JSON validator sample for WinRT #2824

merged 2 commits into from
Jan 31, 2024

Conversation

kennykerr
Copy link
Collaborator

@kennykerr kennykerr commented Jan 31, 2024

This sample follows on from #2815 (article) and demonstrates how you can implement a WinRT-style API in Rust.

This sample component implements the following IDL:

namespace Sample
{
    runtimeclass JsonValidator
    {
        JsonValidator(String schema);
        String Validate(String value);
    }
}

The main takeaways compared to the Win32-style API is that this requires dramatically less code overall and in particular very little unsafe code, greatly simplifying code reviews. The accompanying tests are also greatly simplified as many of the edge cases are handled automatically. This is all due to WinRT's safer type system translating into greater safety guarantees.

The generated bindings.rs are included in this PR for code gen validation and education but would not normally be included in production.

@kennykerr kennykerr merged commit ccfc98a into master Jan 31, 2024
65 checks passed
@kennykerr kennykerr deleted the json_validator_winrt branch January 31, 2024 20:20
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