rodrigocfd / winsafe

Windows API and GUI in safe, idiomatic Rust.
https://crates.io/crates/winsafe
MIT License
518 stars 30 forks source link

`WC::NoValue`? #110

Closed DavisVaughan closed 11 months ago

DavisVaughan commented 11 months ago

Is there a reason that MBC::NoValue exists, but WC::NoValue doesn't?

https://github.com/rodrigocfd/winsafe/blob/4ffb4a2b042570d3aec7b1aba09cac18026f390e/src/kernel/co/consts.rs#L784-L796

https://github.com/rodrigocfd/winsafe/blob/4ffb4a2b042570d3aec7b1aba09cac18026f390e/src/kernel/co/consts.rs#L2249-L2259

According to https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte#parameters:

For the code pages listed below, dwFlags must be 0

Similar to what it says for MultiByteToWideChar, so I think I was expecting NoValue here too

rodrigocfd commented 11 months ago

This boils down to the question of why does NoValue exist, in the first place.

In an ideal world, with a Windows API being perfectly well-designed, there would be no need for NoValue. The zero in any flag would mean the absence of flags, whose possibility would be represented by Option<co::FOO> in Rust's terms.

This is far from the reality, obviously.

So NoValue is an escape hatch for holes in the type system, which works for almost all constant types, but not all, because some of them do have the zero as an actual flag value.

Now,

Is there a reason that MBC::NoValue exists, but WC::NoValue doesn't?

The only reason is that I didn't notice the use case. But you are correct, and I'm implementing right now.