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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fmt
kennykerr committed Sep 23, 2024
commit a4f9cd82651b7980621c98967201d2b787d197a4
24 changes: 12 additions & 12 deletions crates/libs/strings/src/hstring.rs
Original file line number Diff line number Diff line change
@@ -6,18 +6,6 @@ use core::ops::Deref;
#[repr(transparent)]
pub struct HSTRING(pub(crate) *mut HStringHeader);

impl Deref for HSTRING {
type Target = [u16];

fn deref(&self) -> &[u16] {
if let Some(header) = self.as_header() {
unsafe { core::slice::from_raw_parts(header.data, header.len as usize) }
} else {
&[]
}
}
}

impl HSTRING {
/// Create an empty `HSTRING`.
///
@@ -82,6 +70,18 @@ impl HSTRING {
}
}

impl Deref for HSTRING {
type Target = [u16];

fn deref(&self) -> &[u16] {
if let Some(header) = self.as_header() {
unsafe { core::slice::from_raw_parts(header.data, header.len as usize) }
} else {
&[]
}
}
}

impl Default for HSTRING {
fn default() -> Self {
Self::new()