-
Notifications
You must be signed in to change notification settings - Fork 497
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
Feature request: Provide more const
support for string types
#2049
Comments
I'd love to get there. I think we're still waiting for things to stabilize. For example, if I try to make
I'm not sure when the |
Hm, if you don't mind a bit of type verbosity you maybe could use |
Testing a bit on There's some ugliness around error[E0658]: dereferencing raw mutable pointers in constant functions is unstable
--> crates\libs\windows\src\core\strings\hstring.rs:40:22
|
40 | unsafe { (*header).data }
| ^^^^^^^^^^^^^^
|
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable even if the pointer is only read, but manually casting it to With Rust 1.64 released today even |
Thanks, that seems to work: https://github.com/microsoft/windows-rs/compare/const-hstring?expand=1 It just breaks the debug visualizer test for some reason. I'll try to figure that out and then get a PR up. |
@kennykerr I'll take a look at the failure. |
Motivation
w!
allows you to create a&'static HSTRING
, but.as_ptr()
and other conversions don't seem to beconst
, so it doesn't seem possible to get a constPCWSTR
from it, in const context. Currently I'm usingwchar::wchz!
as alternative:PCWSTR::from_raw(wchz!("my string").as_ptr())
. It would be nice to have a built-in way to do this.Another tiny one is to create a const null-
PCWSTR
, butPCWSTR::null
is not marked as const.PCWSTR(std::ptr::null())
is the slightly uglier workaround :)The same should be the case for the other string types (
PWSTR
, and the 8bit string types).null()
,as_ptr()
andis_null()
all can be marked asconst fn
as far as I can tell.Drawbacks
No response
Rationale and alternatives
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: