From f32f083c81a5034530ac33ad2bc460dd234186a5 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 4 May 2025 20:43:32 -0400 Subject: [Rust] More cleanup regarding `BnString` - Removed `to_string` shortcut from `BnString`. - Misc formatting --- rust/src/metadata.rs | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'rust/src/metadata.rs') diff --git a/rust/src/metadata.rs b/rust/src/metadata.rs index cc10885a..b6b3ce61 100644 --- a/rust/src/metadata.rs +++ b/rust/src/metadata.rs @@ -213,7 +213,7 @@ impl Metadata { } } - pub fn get_value_store(&self) -> Result>, ()> { + pub fn get_value_store(&self) -> Result>, ()> { match self.get_type() { MetadataType::KeyValueDataType => { let ptr: *mut BNMetadataValueStore = @@ -230,7 +230,7 @@ impl Metadata { let mut map = HashMap::new(); for i in 0..size { - let key = unsafe { BnString::from_raw(keys[i]) }; + let key = unsafe { BnString::into_string(keys[i]) }; let value = unsafe { Ref::::new(Self { @@ -589,7 +589,7 @@ impl TryFrom<&Metadata> for String { type Error = (); fn try_from(value: &Metadata) -> Result { - value.get_string().map(|s| s.to_string()) + value.get_string().map(|s| s.to_string_lossy().to_string()) } } @@ -637,9 +637,11 @@ impl TryFrom<&Metadata> for Vec { type Error = (); fn try_from(value: &Metadata) -> Result { - value - .get_string_list() - .map(|v| v.into_iter().map(|s| s.to_string()).collect()) + value.get_string_list().map(|v| { + v.into_iter() + .map(|s| s.to_string_lossy().to_string()) + .collect() + }) } } @@ -659,21 +661,11 @@ impl TryFrom<&Metadata> for Array { } } -impl TryFrom<&Metadata> for HashMap> { - type Error = (); - - fn try_from(value: &Metadata) -> Result { - value.get_value_store() - } -} - impl TryFrom<&Metadata> for HashMap> { type Error = (); fn try_from(value: &Metadata) -> Result { - value - .get_value_store() - .map(|m| m.into_iter().map(|(k, v)| (k.to_string(), v)).collect()) + value.get_value_store() } } -- cgit v1.3.1