From 6264254065bbae9d89f51cf3330379b7ace09592 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sat, 3 May 2025 23:15:17 -0400 Subject: [Rust] Return `String` instead of `BnString` for cases where lossy conversion can be tolerated Still need to go and audit all usage, but realistically the most important places to give the user control are with symbols, where the data can come from non utf8 sources This is still incomplete, I just looked for usage of -> BnString so any other variant was omitted. --- rust/src/settings.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'rust/src/settings.rs') diff --git a/rust/src/settings.rs b/rust/src/settings.rs index 8c64f314..4b4d418f 100644 --- a/rust/src/settings.rs +++ b/rust/src/settings.rs @@ -58,8 +58,8 @@ impl Settings { unsafe { BNSettingsSetResourceId(self.handle, resource_id.as_ref().as_ptr() as *mut _) }; } - pub fn serialize_schema(&self) -> BnString { - unsafe { BnString::from_raw(BNSettingsSerializeSchema(self.handle)) } + pub fn serialize_schema(&self) -> String { + unsafe { BnString::into_string(BNSettingsSerializeSchema(self.handle)) } } pub fn deserialize_schema(&self, schema: S) -> bool { @@ -184,7 +184,7 @@ impl Settings { } } - pub fn get_string(&self, key: S) -> BnString { + pub fn get_string(&self, key: S) -> String { self.get_string_with_opts(key, &mut QueryOptions::default()) } @@ -192,7 +192,7 @@ impl Settings { &self, key: S, options: &mut QueryOptions, - ) -> BnString { + ) -> String { let key = key.into_bytes_with_nul(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -203,7 +203,7 @@ impl Settings { _ => std::ptr::null_mut(), }; unsafe { - BnString::from_raw(BNSettingsGetString( + BnString::into_string(BNSettingsGetString( self.handle, key.as_ref().as_ptr() as *mut _, view_ptr, @@ -248,7 +248,7 @@ impl Settings { } } - pub fn get_json(&self, key: S) -> BnString { + pub fn get_json(&self, key: S) -> String { self.get_json_with_opts(key, &mut QueryOptions::default()) } @@ -256,7 +256,7 @@ impl Settings { &self, key: S, options: &mut QueryOptions, - ) -> BnString { + ) -> String { let key = key.into_bytes_with_nul(); let view_ptr = match options.view.as_ref() { Some(view) => view.handle, @@ -267,7 +267,7 @@ impl Settings { _ => std::ptr::null_mut(), }; unsafe { - BnString::from_raw(BNSettingsGetJson( + BnString::into_string(BNSettingsGetJson( self.handle, key.as_ref().as_ptr() as *mut _, view_ptr, @@ -479,11 +479,11 @@ impl Settings { } } - pub fn get_property_string(&self, key: S, property: S) -> BnString { + pub fn get_property_string(&self, key: S, property: S) -> String { let key = key.into_bytes_with_nul(); let property = property.into_bytes_with_nul(); unsafe { - BnString::from_raw(BNSettingsQueryPropertyString( + BnString::into_string(BNSettingsQueryPropertyString( self.handle, key.as_ref().as_ptr() as *mut _, property.as_ref().as_ptr() as *mut _, -- cgit v1.3.1