diff options
| author | Mason Reed <mason@vector35.com> | 2025-05-07 19:22:21 -0400 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2025-05-12 17:45:24 -0400 |
| commit | 2f214f6c9935e8ce8df4732cde44a540a003258c (patch) | |
| tree | 6fe319433ef0d2ad75fcc58a50eaa632bb627ec9 /rust/src/repository.rs | |
| parent | b4cf0be8816182c9efca037e27e9439482f8bf36 (diff) | |
[Rust] Reduce usage of `IntoCStr` in function signatures
This is being done to reduce complexity in function signatures, specifically many of the strings we are passing ultimately should be new types themselves instead of "just strings", things such as type ids.
Another place which was confusing was dealing with filesystem related APIs, this commit turns most of those params into a stricter `Path` type.
This is bringing the rust api more inline with both python and C++, where the wrapper eagerly converts the string into the languages standard string type.
Special consideration must be made for symbols or other possible non utf-8 objects.
This commit will be followed up with one that adds the `IntoCStr` bound on API's we want to keep as invalid utf-8 so we can for example, get section by name on a section with invalid utf-8.
Diffstat (limited to 'rust/src/repository.rs')
| -rw-r--r-- | rust/src/repository.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/rust/src/repository.rs b/rust/src/repository.rs index 8d9a8f40..a29be323 100644 --- a/rust/src/repository.rs +++ b/rust/src/repository.rs @@ -3,6 +3,7 @@ mod plugin; use std::ffi::c_char; use std::fmt::Debug; +use std::path::{Path, PathBuf}; use std::ptr::NonNull; use binaryninjacore_sys::*; @@ -38,10 +39,11 @@ impl Repository { } /// String local path to store the given plugin repository - pub fn path(&self) -> String { + pub fn path(&self) -> PathBuf { let result = unsafe { BNRepositoryGetRepoPath(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::into_string(result as *mut c_char) } + let result_str = unsafe { BnString::into_string(result as *mut c_char) }; + PathBuf::from(result_str) } /// List of RepoPlugin objects contained within this repository @@ -52,18 +54,18 @@ impl Repository { unsafe { Array::new(result, count, ()) } } - pub fn plugin_by_path<S: IntoCStr>(&self, path: S) -> Option<Ref<RepositoryPlugin>> { + pub fn plugin_by_path(&self, path: &Path) -> Option<Ref<RepositoryPlugin>> { let path = path.to_cstr(); let result = unsafe { BNRepositoryGetPluginByPath(self.handle.as_ptr(), path.as_ptr()) }; NonNull::new(result).map(|h| unsafe { RepositoryPlugin::ref_from_raw(h) }) } - // TODO: Make this a PathBuf? /// String full path the repository - pub fn full_path(&self) -> String { + pub fn full_path(&self) -> PathBuf { let result = unsafe { BNRepositoryGetPluginsPath(self.handle.as_ptr()) }; assert!(!result.is_null()); - unsafe { BnString::into_string(result as *mut c_char) } + let result_str = unsafe { BnString::into_string(result as *mut c_char) }; + PathBuf::from(result_str) } } |
