From a826c589dfc10c542deba7ca3343a462e02d6bde Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 4 May 2025 19:10:56 -0400 Subject: [Rust] Simplify `BnStrCompatible` trait Followup to https://github.com/Vector35/binaryninja-api/pull/5897/ This simplifies usage of the trait in user code, should just be able to `to_cstr` to get the cstr repr and then call `as_ptr`. Co-authored-by: Michael Krasnitski --- rust/src/repository/manager.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'rust/src/repository') diff --git a/rust/src/repository/manager.rs b/rust/src/repository/manager.rs index 59889162..e5911802 100644 --- a/rust/src/repository/manager.rs +++ b/rust/src/repository/manager.rs @@ -1,6 +1,6 @@ use crate::rc::{Array, Ref, RefCountable}; use crate::repository::Repository; -use crate::string::BnStrCompatible; +use crate::string::AsCStr; use binaryninjacore_sys::{ BNCreateRepositoryManager, BNFreeRepositoryManager, BNGetRepositoryManager, BNNewRepositoryManagerReference, BNRepositoryGetRepositoryByPath, BNRepositoryManager, @@ -29,8 +29,8 @@ impl RepositoryManager { Ref::new(Self { handle }) } - pub fn new(plugins_path: S) -> Ref { - let plugins_path = plugins_path.into_bytes_with_nul(); + pub fn new(plugins_path: S) -> Ref { + let plugins_path = plugins_path.to_cstr(); let result = unsafe { BNCreateRepositoryManager(plugins_path.as_ref().as_ptr() as *const c_char) }; unsafe { Self::ref_from_raw(NonNull::new(result).unwrap()) } @@ -61,13 +61,9 @@ impl RepositoryManager { /// * `repository_path` - path to where the repository will be stored on disk locally /// /// Returns true if the repository was successfully added, false otherwise. - pub fn add_repository( - &self, - url: U, - repository_path: P, - ) -> bool { - let url = url.into_bytes_with_nul(); - let repo_path = repository_path.into_bytes_with_nul(); + pub fn add_repository(&self, url: U, repository_path: P) -> bool { + let url = url.to_cstr(); + let repo_path = repository_path.to_cstr(); unsafe { BNRepositoryManagerAddRepository( self.handle.as_ptr(), @@ -77,8 +73,8 @@ impl RepositoryManager { } } - pub fn repository_by_path(&self, path: P) -> Option { - let path = path.into_bytes_with_nul(); + pub fn repository_by_path(&self, path: P) -> Option { + let path = path.to_cstr(); let result = unsafe { BNRepositoryGetRepositoryByPath( self.handle.as_ptr(), -- cgit v1.3.1