microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.43k stars 493 forks source link

Simplify for optional value types #292

Open kennykerr opened 4 years ago

kennykerr commented 4 years ago

WinRT uses IReference<T> parameter and field types to indicate that a given argument/value is optional. This should be expressed in Rust using Option<T>. In particular, we should add Param specializations (as we do for strings) for IReference<T> input parameters to allow parameters to either accept T or None.

This builds on #92.

kennykerr commented 4 months ago

Closing this old issue - doesn't seem to be much demand for such API support. Let me know if you have thoughts to the contrary. 😊

kennykerr commented 2 months ago

Reopening as there's renewed demand for WinRT type system support. Doing what I described here https://github.com/microsoft/windows-rs/issues/2310#issuecomment-1406625343 should be a little easier with a stock implementation.

kennykerr commented 1 month ago

I think that IReference<T> support can be limited to "optional" behavior rather than the double mean used by Xaml and .NET for polymorphic value types. That simplifies the implementation and lets us treat IReference<T> more uniformly in Rust as semantically equivalent to Option<T>. The bindings can then be simplified to model IReference<T> properties as Option getters and setters rather than Param<IReference<T>> and Result<IReference<T>> respectively.