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/collaboration/group.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'rust/src/collaboration/group.rs') diff --git a/rust/src/collaboration/group.rs b/rust/src/collaboration/group.rs index 9fb287a7..94253519 100644 --- a/rust/src/collaboration/group.rs +++ b/rust/src/collaboration/group.rs @@ -1,6 +1,6 @@ use super::Remote; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{BnStrCompatible, BnString}; +use crate::string::{AsCStr, BnString}; use binaryninjacore_sys::*; use std::ffi::c_char; use std::fmt; @@ -50,8 +50,8 @@ impl RemoteGroup { /// Set group name /// You will need to push the group to update the Remote. - pub fn set_name(&self, name: U) { - let name = name.into_bytes_with_nul(); + pub fn set_name(&self, name: U) { + let name = name.to_cstr(); unsafe { BNCollaborationGroupSetName( self.handle.as_ptr(), @@ -90,12 +90,9 @@ impl RemoteGroup { pub fn set_users(&self, usernames: I) -> Result<(), ()> where I: IntoIterator, - I::Item: BnStrCompatible, + I::Item: AsCStr, { - let usernames: Vec<_> = usernames - .into_iter() - .map(|u| u.into_bytes_with_nul()) - .collect(); + 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) @@ -114,8 +111,8 @@ impl RemoteGroup { } /// Test if a group has a user with the given username - pub fn contains_user(&self, username: U) -> bool { - let username = username.into_bytes_with_nul(); + pub fn contains_user(&self, username: U) -> bool { + let username = username.to_cstr(); unsafe { BNCollaborationGroupContainsUser( self.handle.as_ptr(), -- cgit v1.3.1