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/database/snapshot.rs | 4 ++-- rust/src/database/undo.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'rust/src/database') diff --git a/rust/src/database/snapshot.rs b/rust/src/database/snapshot.rs index 35b0dc46..3768138c 100644 --- a/rust/src/database/snapshot.rs +++ b/rust/src/database/snapshot.rs @@ -45,8 +45,8 @@ impl Snapshot { } /// Get the displayed snapshot name - pub fn name(&self) -> BnString { - unsafe { BnString::from_raw(BNGetSnapshotName(self.handle.as_ptr())) } + pub fn name(&self) -> String { + unsafe { BnString::into_string(BNGetSnapshotName(self.handle.as_ptr())) } } /// Set the displayed snapshot name diff --git a/rust/src/database/undo.rs b/rust/src/database/undo.rs index 727a777b..a2001b72 100644 --- a/rust/src/database/undo.rs +++ b/rust/src/database/undo.rs @@ -26,10 +26,10 @@ impl UndoEntry { Ref::new(Self { handle }) } - pub fn id(&self) -> BnString { + pub fn id(&self) -> String { let result = unsafe { BNUndoEntryGetId(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } pub fn actions(&self) -> Array { @@ -115,10 +115,10 @@ impl UndoAction { } /// Gets the [`UndoAction`] summary as text rather than [`InstructionTextToken`]'s. - pub fn summary_as_string(&self) -> BnString { + pub fn summary_as_string(&self) -> String { let result = unsafe { BNUndoActionGetSummaryText(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::from_raw(result) } + unsafe { BnString::into_string(result) } } } -- cgit v1.3.1