Skip to content

Commit

Permalink
as_wide
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Aug 5, 2024
1 parent cad6f75 commit 63083eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/libs/registry/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ impl Value {
pub fn set_ty(&mut self, ty: Type) {
self.ty = ty;
}

/// Gets the value as a slice of u16 for raw wide characters.
pub fn as_wide(&self) -> &[u16] {
self.data.as_wide()
}
}

impl core::ops::Deref for Value {
Expand Down
5 changes: 5 additions & 0 deletions crates/tests/registry/tests/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,10 @@ fn value() -> Result<()> {
(Type::String, 16)
);

let abc = Value::try_from("abc")?;
assert_eq!(abc.as_wide(), &[97, 98, 99, 0]);
let abc = Value::try_from(h!("abcd"))?;
assert_eq!(abc.as_wide(), &[97, 98, 99, 100, 0]);

Ok(())
}

0 comments on commit 63083eb

Please sign in to comment.