diff options
| author | Mason Reed <mason@vector35.com> | 2025-05-04 19:10:56 -0400 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2025-05-12 17:45:24 -0400 |
| commit | a826c589dfc10c542deba7ca3343a462e02d6bde (patch) | |
| tree | f116254bef39f787268bbecc5eac19da310db9ce /rust/src/repository | |
| parent | 28b3c4044af06fdc32c9c85bf8381b5058306427 (diff) | |
[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 <michael.krasnitski@gmail.com>
Diffstat (limited to 'rust/src/repository')
| -rw-r--r-- | rust/src/repository/manager.rs | 20 |
1 files changed, 8 insertions, 12 deletions
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<S: BnStrCompatible>(plugins_path: S) -> Ref<Self> { - let plugins_path = plugins_path.into_bytes_with_nul(); + pub fn new<S: AsCStr>(plugins_path: S) -> Ref<Self> { + 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<U: BnStrCompatible, P: BnStrCompatible>( - &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<U: AsCStr, P: AsCStr>(&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<P: BnStrCompatible>(&self, path: P) -> Option<Repository> { - let path = path.into_bytes_with_nul(); + pub fn repository_by_path<P: AsCStr>(&self, path: P) -> Option<Repository> { + let path = path.to_cstr(); let result = unsafe { BNRepositoryGetRepositoryByPath( self.handle.as_ptr(), |
