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/collaboration/group.rs | |
| 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/collaboration/group.rs')
| -rw-r--r-- | rust/src/collaboration/group.rs | 17 |
1 files changed, 7 insertions, 10 deletions
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<U: BnStrCompatible>(&self, name: U) { - let name = name.into_bytes_with_nul(); + pub fn set_name<U: AsCStr>(&self, name: U) { + let name = name.to_cstr(); unsafe { BNCollaborationGroupSetName( self.handle.as_ptr(), @@ -90,12 +90,9 @@ impl RemoteGroup { pub fn set_users<I>(&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<U: BnStrCompatible>(&self, username: U) -> bool { - let username = username.into_bytes_with_nul(); + pub fn contains_user<U: AsCStr>(&self, username: U) -> bool { + let username = username.to_cstr(); unsafe { BNCollaborationGroupContainsUser( self.handle.as_ptr(), |
