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/collaboration/group.rs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'rust/src/collaboration/group.rs') diff --git a/rust/src/collaboration/group.rs b/rust/src/collaboration/group.rs index 94253519..b8b32c7a 100644 --- a/rust/src/collaboration/group.rs +++ b/rust/src/collaboration/group.rs @@ -2,7 +2,6 @@ use super::Remote; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; use crate::string::{AsCStr, BnString}; use binaryninjacore_sys::*; -use std::ffi::c_char; use std::fmt; use std::fmt::{Display, Formatter}; use std::ptr::NonNull; @@ -52,12 +51,7 @@ impl RemoteGroup { /// You will need to push the group to update the Remote. pub fn set_name(&self, name: U) { let name = name.to_cstr(); - unsafe { - BNCollaborationGroupSetName( - self.handle.as_ptr(), - name.as_ref().as_ptr() as *const c_char, - ) - } + unsafe { BNCollaborationGroupSetName(self.handle.as_ptr(), name.as_ptr()) } } /// Get list of users in the group @@ -93,10 +87,7 @@ impl RemoteGroup { I::Item: AsCStr, { let usernames: Vec<_> = usernames.into_iter().map(|u| u.to_cstr()).collect(); - let mut usernames_raw: Vec<_> = usernames - .iter() - .map(|s| s.as_ref().as_ptr() as *const c_char) - .collect(); + let mut usernames_raw: Vec<_> = usernames.iter().map(|s| s.as_ptr()).collect(); // TODO: This should only fail if collaboration is not supported. // TODO: Because you should not have a RemoteGroup at that point we can ignore? // TODO: Do you need any permissions to do this? @@ -113,12 +104,7 @@ impl RemoteGroup { /// Test if a group has a user with the given username pub fn contains_user(&self, username: U) -> bool { let username = username.to_cstr(); - unsafe { - BNCollaborationGroupContainsUser( - self.handle.as_ptr(), - username.as_ref().as_ptr() as *const c_char, - ) - } + unsafe { BNCollaborationGroupContainsUser(self.handle.as_ptr(), username.as_ptr()) } } } -- cgit v1.3.1