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 Deref implementation for HSTRING #3291

Merged
merged 8 commits into from
Sep 23, 2024
Merged

Add Deref implementation for HSTRING #3291

merged 8 commits into from
Sep 23, 2024

Conversation

kennykerr
Copy link
Collaborator

@kennykerr kennykerr commented Sep 23, 2024

The HSTRING type represents a UTF-16 string that is modeled as a [u16] slice in Rust. This update replaces the as_wide method to retrieve the HSTRING as a slice with a Deref implementation. This makes it a lot easier to work with an HSTRING in Rust as conversion is implicit in many cases.

The same is done for BSTR for consistency and code reduction.

Fixes: rust-lang/rustup#3896 (comment)

@kennykerr
Copy link
Collaborator Author

kennykerr commented Sep 23, 2024

Build break is due to unrelated Rust nightly update - investigating.

Workaround is here: #3292

@djc
Copy link

djc commented Sep 23, 2024

Nice!

@kennykerr kennykerr merged commit 0f7466c into master Sep 23, 2024
81 checks passed
@kennykerr kennykerr deleted the hstring-deref branch September 23, 2024 23:01

pub fn len(&self) -> usize {
if self.0.is_null() {
fn deref(&self) -> &[u16] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this signature rather than its more conventional spelling

fn deref(&self) -> &Self::Target

?

I'm just curious if there's a particular reason.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason, just seemed more succinct in this case.

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.

3 participants