Skip to content

Add Deref implementation for HSTRING - #3291

Merged
Kenny Kerr (kennykerr) merged 8 commits into
masterfrom
hstring-deref
Sep 23, 2024
Merged

Kenny Kerr (kennykerr) merged 8 commits into
masterfrom
hstring-deref

Conversation

@kennykerr

@kennykerr Kenny Kerr (kennykerr) commented Sep 23, 2024 •

Copy link
Copy Markdown
Collaborator

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

Kenny Kerr (kennykerr) commented Sep 23, 2024 •

Copy link
Copy Markdown
Collaborator Author

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

Workaround is here: #3292

@djc

Copy link
Copy Markdown

Nice!

@kennykerr
Kenny Kerr (kennykerr) merged commit 0f7466c into master Sep 23, 2024
@kennykerr
Kenny Kerr (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
Copy Markdown
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
Copy Markdown
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