From 788a8b7091bbdde77817030e0836d7a7a786fd99 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 4 May 2025 19:47:55 -0400 Subject: [Rust] Simplify usage surrounding c strings `cstring.as_ref().as_ptr() as *const c_char` -> `cstring.as_ptr()` `cstring.as_ref().as_ptr() as *mut _` -> `cstring.as_ptr()` `cstring.as_ptr() as *const c_char` -> `cstring.as_ptr()` With a few fixes for cstrings that might be dropped prematurely. --- rust/src/repository/manager.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'rust/src/repository') diff --git a/rust/src/repository/manager.rs b/rust/src/repository/manager.rs index e5911802..29c73605 100644 --- a/rust/src/repository/manager.rs +++ b/rust/src/repository/manager.rs @@ -7,7 +7,6 @@ use binaryninjacore_sys::{ BNRepositoryManagerAddRepository, BNRepositoryManagerCheckForUpdates, BNRepositoryManagerGetDefaultRepository, BNRepositoryManagerGetRepositories, }; -use std::ffi::c_char; use std::fmt::Debug; use std::ptr::NonNull; @@ -31,8 +30,7 @@ impl RepositoryManager { 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) }; + let result = unsafe { BNCreateRepositoryManager(plugins_path.as_ptr()) }; unsafe { Self::ref_from_raw(NonNull::new(result).unwrap()) } } @@ -65,22 +63,14 @@ impl RepositoryManager { let url = url.to_cstr(); let repo_path = repository_path.to_cstr(); unsafe { - BNRepositoryManagerAddRepository( - self.handle.as_ptr(), - url.as_ref().as_ptr() as *const c_char, - repo_path.as_ref().as_ptr() as *const c_char, - ) + BNRepositoryManagerAddRepository(self.handle.as_ptr(), url.as_ptr(), repo_path.as_ptr()) } } pub fn repository_by_path(&self, path: P) -> Option { let path = path.to_cstr(); - let result = unsafe { - BNRepositoryGetRepositoryByPath( - self.handle.as_ptr(), - path.as_ref().as_ptr() as *const c_char, - ) - }; + let result = + unsafe { BNRepositoryGetRepositoryByPath(self.handle.as_ptr(), path.as_ptr()) }; NonNull::new(result).map(|raw| unsafe { Repository::from_raw(raw) }) } -- cgit v1.3.1