Skip to content

Conversation

kennykerr
Copy link
Collaborator

This update adds first-class support for VARIANT and PROPVARIANT to the windows-core crate and by extension the windows crate. This does not affect the windows-sys crate.

Creating a variant is now very simple:

let v = VARIANT::from(345u16);

The TryFrom trait can be used to query for an expected type:

assert_eq!(u16::try_from(&v)?, 345u16);

Most primitive types, including BSTR, are supported:

let v = VARIANT::from(BSTR::from("hello"));
assert_eq!(BSTR::try_from(&v)?, "hello");

Natural type coercion is also support:

let v = VARIANT::from(3.5f64);
assert_eq!(BSTR::try_from(&v)?, "3.5");

Standard traits like Drop, Clone, PartialEq, and Debug are provided:

assert_eq!(format!("{v:?}"), "VARIANT { type: 5, value: 3.5 }");

Fixes: #539

@kennykerr kennykerr merged commit e69e8e6 into master Jan 11, 2024
@kennykerr kennykerr deleted the variant-core branch January 11, 2024 14:33
@mwcampbell
Copy link

For what it's worth, if this is released in its current state, AccessKit won't be able to upgrade to this version, unless there's some escape hatch I can still use to create a VARIANT from an IUnknown and return that VARIANT in an implemented interface method.

@kennykerr
Copy link
Collaborator Author

#2788 adds support for IUnknown - is that what you mean?

@mwcampbell
Copy link

Yes, thanks.

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.

Simplify use of VARIANT

2 participants