diff options
| author | Mason Reed <mason@vector35.com> | 2025-05-05 13:17:30 -0400 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2025-05-12 17:45:24 -0400 |
| commit | 9dadf92c16da5cd21def79ae39ca98803c9208ec (patch) | |
| tree | 3874a659bcb3818f43c1a46ab3ef081b99b47154 /rust/src/collaboration | |
| parent | 9f5491a56f6af1fa9b030f23d40150673a52aaa1 (diff) | |
[Rust] Rename `AsCStr` to `IntoCStr`
Diffstat (limited to 'rust/src/collaboration')
| -rw-r--r-- | rust/src/collaboration/changeset.rs | 4 | ||||
| -rw-r--r-- | rust/src/collaboration/file.rs | 26 | ||||
| -rw-r--r-- | rust/src/collaboration/folder.rs | 6 | ||||
| -rw-r--r-- | rust/src/collaboration/group.rs | 8 | ||||
| -rw-r--r-- | rust/src/collaboration/merge.rs | 10 | ||||
| -rw-r--r-- | rust/src/collaboration/project.rs | 56 | ||||
| -rw-r--r-- | rust/src/collaboration/remote.rs | 40 | ||||
| -rw-r--r-- | rust/src/collaboration/snapshot.rs | 4 | ||||
| -rw-r--r-- | rust/src/collaboration/sync.rs | 20 | ||||
| -rw-r--r-- | rust/src/collaboration/user.rs | 6 |
10 files changed, 90 insertions, 90 deletions
diff --git a/rust/src/collaboration/changeset.rs b/rust/src/collaboration/changeset.rs index 0db384cb..b07f23de 100644 --- a/rust/src/collaboration/changeset.rs +++ b/rust/src/collaboration/changeset.rs @@ -6,7 +6,7 @@ use super::{RemoteFile, RemoteUser}; use crate::database::snapshot::SnapshotId; use crate::database::Database; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; /// A collection of snapshots in a local database #[repr(transparent)] @@ -65,7 +65,7 @@ impl Changeset { } /// Set the name of the changeset, e.g. in a name changeset function. - pub fn set_name<S: AsCStr>(&self, value: S) -> bool { + pub fn set_name<S: IntoCStr>(&self, value: S) -> bool { let value = value.to_cstr(); unsafe { BNCollaborationChangesetSetName(self.handle.as_ptr(), value.as_ptr()) } } diff --git a/rust/src/collaboration/file.rs b/rust/src/collaboration/file.rs index 251b4f7d..699b34b8 100644 --- a/rust/src/collaboration/file.rs +++ b/rust/src/collaboration/file.rs @@ -16,7 +16,7 @@ use crate::file_metadata::FileMetadata; use crate::progress::{NoProgressCallback, ProgressCallback, SplitProgressBuilder}; use crate::project::file::ProjectFile; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; pub type RemoteFileType = BNRemoteFileType; @@ -94,7 +94,7 @@ impl RemoteFile { success.then_some(()).ok_or(()) } - pub fn set_metadata<S: AsCStr>(&self, folder: S) -> Result<(), ()> { + pub fn set_metadata<S: IntoCStr>(&self, folder: S) -> Result<(), ()> { let folder_raw = folder.to_cstr(); let success = unsafe { BNRemoteFileSetMetadata(self.handle.as_ptr(), folder_raw.as_ptr()) }; success.then_some(()).ok_or(()) @@ -185,7 +185,7 @@ impl RemoteFile { } /// Set the description of the file. You will need to push the file to update the remote version. - pub fn set_name<S: AsCStr>(&self, name: S) -> Result<(), ()> { + pub fn set_name<S: IntoCStr>(&self, name: S) -> Result<(), ()> { let name = name.to_cstr(); let success = unsafe { BNRemoteFileSetName(self.handle.as_ptr(), name.as_ptr()) }; success.then_some(()).ok_or(()) @@ -199,7 +199,7 @@ impl RemoteFile { } /// Set the description of the file. You will need to push the file to update the remote version. - pub fn set_description<S: AsCStr>(&self, description: S) -> Result<(), ()> { + pub fn set_description<S: IntoCStr>(&self, description: S) -> Result<(), ()> { let description = description.to_cstr(); let success = unsafe { BNRemoteFileSetDescription(self.handle.as_ptr(), description.as_ptr()) }; @@ -249,7 +249,7 @@ impl RemoteFile { /// Get a specific Snapshot in the File by its id /// /// NOTE: If snapshots have not been pulled, they will be pulled upon calling this. - pub fn snapshot_by_id<S: AsCStr>(&self, id: S) -> Result<Option<Ref<RemoteSnapshot>>, ()> { + pub fn snapshot_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteSnapshot>>, ()> { // TODO: This sync should be removed? if !self.has_pulled_snapshots() { self.pull_snapshots()?; @@ -295,9 +295,9 @@ impl RemoteFile { parent_ids: I, ) -> Result<Ref<RemoteSnapshot>, ()> where - S: AsCStr, + S: IntoCStr, I: IntoIterator, - I::Item: AsCStr, + I::Item: IntoCStr, { self.create_snapshot_with_progress( name, @@ -327,10 +327,10 @@ impl RemoteFile { mut progress: P, ) -> Result<Ref<RemoteSnapshot>, ()> where - S: AsCStr, + S: IntoCStr, P: ProgressCallback, I: IntoIterator, - I::Item: AsCStr, + I::Item: IntoCStr, { let name = name.to_cstr(); let parent_ids: Vec<_> = parent_ids.into_iter().map(|id| id.to_cstr()).collect(); @@ -405,7 +405,7 @@ impl RemoteFile { /// * `progress_function` - Function to call for progress updates pub fn download<S>(&self, db_path: S) -> Result<Ref<FileMetadata>, ()> where - S: AsCStr, + S: IntoCStr, { sync::download_file(self, db_path) } @@ -422,14 +422,14 @@ impl RemoteFile { progress_function: F, ) -> Result<Ref<FileMetadata>, ()> where - S: AsCStr, + S: IntoCStr, F: ProgressCallback, { sync::download_file_with_progress(self, db_path, progress_function) } /// Download a remote file and save it to a BNDB at the given `path`, returning the associated [`FileMetadata`]. - pub fn download_database<S: AsCStr>(&self, path: S) -> Result<Ref<FileMetadata>, ()> { + pub fn download_database<S: IntoCStr>(&self, path: S) -> Result<Ref<FileMetadata>, ()> { let file = self.download(path)?; let database = file.database().ok_or(())?; self.sync(&database, DatabaseConflictHandlerFail, NoNameChangeset)?; @@ -439,7 +439,7 @@ impl RemoteFile { // TODO: This might be a bad helper... maybe remove... // TODO: AsRef<Path> /// Download a remote file and save it to a BNDB at the given `path`. - pub fn download_database_with_progress<S: AsCStr>( + pub fn download_database_with_progress<S: IntoCStr>( &self, path: S, progress: impl ProgressCallback, diff --git a/rust/src/collaboration/folder.rs b/rust/src/collaboration/folder.rs index b5fde3b4..35ff0788 100644 --- a/rust/src/collaboration/folder.rs +++ b/rust/src/collaboration/folder.rs @@ -4,7 +4,7 @@ use std::ptr::NonNull; use crate::project::folder::ProjectFolder; use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; #[repr(transparent)] pub struct RemoteFolder { @@ -103,7 +103,7 @@ impl RemoteFolder { } /// Set the display name of the folder. You will need to push the folder to update the remote version. - pub fn set_name<S: AsCStr>(&self, name: S) -> Result<(), ()> { + pub fn set_name<S: IntoCStr>(&self, name: S) -> Result<(), ()> { let name = name.to_cstr(); let success = unsafe { BNRemoteFolderSetName(self.handle.as_ptr(), name.as_ptr()) }; success.then_some(()).ok_or(()) @@ -117,7 +117,7 @@ impl RemoteFolder { } /// Set the description of the folder. You will need to push the folder to update the remote version. - pub fn set_description<S: AsCStr>(&self, description: S) -> Result<(), ()> { + pub fn set_description<S: IntoCStr>(&self, description: S) -> Result<(), ()> { let description = description.to_cstr(); let success = unsafe { BNRemoteFolderSetDescription(self.handle.as_ptr(), description.as_ptr()) }; diff --git a/rust/src/collaboration/group.rs b/rust/src/collaboration/group.rs index b8b32c7a..08efa079 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::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use binaryninjacore_sys::*; use std::fmt; use std::fmt::{Display, Formatter}; @@ -49,7 +49,7 @@ impl RemoteGroup { /// Set group name /// You will need to push the group to update the Remote. - pub fn set_name<U: AsCStr>(&self, name: U) { + pub fn set_name<U: IntoCStr>(&self, name: U) { let name = name.to_cstr(); unsafe { BNCollaborationGroupSetName(self.handle.as_ptr(), name.as_ptr()) } } @@ -84,7 +84,7 @@ impl RemoteGroup { pub fn set_users<I>(&self, usernames: I) -> Result<(), ()> where I: IntoIterator, - I::Item: AsCStr, + I::Item: IntoCStr, { let usernames: Vec<_> = usernames.into_iter().map(|u| u.to_cstr()).collect(); let mut usernames_raw: Vec<_> = usernames.iter().map(|s| s.as_ptr()).collect(); @@ -102,7 +102,7 @@ impl RemoteGroup { } /// Test if a group has a user with the given username - pub fn contains_user<U: AsCStr>(&self, username: U) -> bool { + pub fn contains_user<U: IntoCStr>(&self, username: U) -> bool { let username = username.to_cstr(); unsafe { BNCollaborationGroupContainsUser(self.handle.as_ptr(), username.as_ptr()) } } diff --git a/rust/src/collaboration/merge.rs b/rust/src/collaboration/merge.rs index 2fb5b3de..9ebf4cda 100644 --- a/rust/src/collaboration/merge.rs +++ b/rust/src/collaboration/merge.rs @@ -4,7 +4,7 @@ use std::ptr::NonNull; use crate::database::{snapshot::Snapshot, Database}; use crate::file_metadata::FileMetadata; use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; pub type MergeConflictDataType = BNMergeConflictDataType; @@ -48,7 +48,7 @@ impl MergeConflict { NonNull::new(result).map(|handle| unsafe { Snapshot::from_raw(handle) }) } - pub fn path_item_string<S: AsCStr>(&self, path: S) -> Result<BnString, ()> { + pub fn path_item_string<S: IntoCStr>(&self, path: S) -> Result<BnString, ()> { let path = path.to_cstr(); let result = unsafe { BNAnalysisMergeConflictGetPathItemString(self.handle.as_ptr(), path.as_ptr()) @@ -119,7 +119,7 @@ impl MergeConflict { } /// Call this when you've resolved the conflict to save the result - pub fn success<S: AsCStr>(&self, value: S) -> Result<(), ()> { + pub fn success<S: IntoCStr>(&self, value: S) -> Result<(), ()> { let value = value.to_cstr(); let success = unsafe { BNAnalysisMergeConflictSuccess(self.handle.as_ptr(), value.as_ptr()) }; @@ -127,7 +127,7 @@ impl MergeConflict { } // TODO: Make a safe version of this that checks the path and if it holds a number - pub unsafe fn get_path_item_number<S: AsCStr>(&self, path_key: S) -> Option<u64> { + pub unsafe fn get_path_item_number<S: IntoCStr>(&self, path_key: S) -> Option<u64> { let path_key = path_key.to_cstr(); let value = unsafe { BNAnalysisMergeConflictGetPathItem(self.handle.as_ptr(), path_key.as_ptr()) }; @@ -138,7 +138,7 @@ impl MergeConflict { } } - pub unsafe fn get_path_item_string<S: AsCStr>(&self, path_key: S) -> Option<BnString> { + pub unsafe fn get_path_item_string<S: IntoCStr>(&self, path_key: S) -> Option<BnString> { let path_key = path_key.to_cstr(); let value = unsafe { BNAnalysisMergeConflictGetPathItemString(self.handle.as_ptr(), path_key.as_ptr()) diff --git a/rust/src/collaboration/project.rs b/rust/src/collaboration/project.rs index fce2a5f6..3d34da9e 100644 --- a/rust/src/collaboration/project.rs +++ b/rust/src/collaboration/project.rs @@ -15,7 +15,7 @@ use crate::file_metadata::FileMetadata; use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::project::Project; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; #[repr(transparent)] pub struct RemoteProject { @@ -136,7 +136,7 @@ impl RemoteProject { } /// Set the description of the file. You will need to push the file to update the remote version. - pub fn set_name<S: AsCStr>(&self, name: S) -> Result<(), ()> { + pub fn set_name<S: IntoCStr>(&self, name: S) -> Result<(), ()> { let name = name.to_cstr(); let success = unsafe { BNRemoteProjectSetName(self.handle.as_ptr(), name.as_ptr()) }; success.then_some(()).ok_or(()) @@ -150,7 +150,7 @@ impl RemoteProject { } /// Set the description of the file. You will need to push the file to update the remote version. - pub fn set_description<S: AsCStr>(&self, description: S) -> Result<(), ()> { + pub fn set_description<S: IntoCStr>(&self, description: S) -> Result<(), ()> { let description = description.to_cstr(); let success = unsafe { BNRemoteProjectSetDescription(self.handle.as_ptr(), description.as_ptr()) }; @@ -221,7 +221,7 @@ impl RemoteProject { /// /// NOTE: If the project has not been opened, it will be opened upon calling this. /// NOTE: If files have not been pulled, they will be pulled upon calling this. - pub fn get_file_by_id<S: AsCStr>(&self, id: S) -> Result<Option<Ref<RemoteFile>>, ()> { + pub fn get_file_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteFile>>, ()> { // TODO: This sync should be removed? if !self.has_pulled_files() { self.pull_files()?; @@ -235,7 +235,7 @@ impl RemoteProject { /// /// NOTE: If the project has not been opened, it will be opened upon calling this. /// NOTE: If files have not been pulled, they will be pulled upon calling this. - pub fn get_file_by_name<S: AsCStr>(&self, name: S) -> Result<Option<Ref<RemoteFile>>, ()> { + pub fn get_file_by_name<S: IntoCStr>(&self, name: S) -> Result<Option<Ref<RemoteFile>>, ()> { // TODO: This sync should be removed? if !self.has_pulled_files() { self.pull_files()?; @@ -292,9 +292,9 @@ impl RemoteProject { file_type: RemoteFileType, ) -> Result<Ref<RemoteFile>, ()> where - F: AsCStr, - N: AsCStr, - D: AsCStr, + F: IntoCStr, + N: IntoCStr, + D: IntoCStr, { self.create_file_with_progress( filename, @@ -329,9 +329,9 @@ impl RemoteProject { mut progress: P, ) -> Result<Ref<RemoteFile>, ()> where - F: AsCStr, - N: AsCStr, - D: AsCStr, + F: IntoCStr, + N: IntoCStr, + D: IntoCStr, P: ProgressCallback, { // TODO: This sync should be removed? @@ -367,8 +367,8 @@ impl RemoteProject { pub fn push_file<I, K, V>(&self, file: &RemoteFile, extra_fields: I) -> Result<(), ()> where I: Iterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, { // TODO: This sync should be removed? self.open()?; @@ -421,7 +421,7 @@ impl RemoteProject { /// /// NOTE: If the project has not been opened, it will be opened upon calling this. /// NOTE: If folders have not been pulled, they will be pulled upon calling this. - pub fn get_folder_by_id<S: AsCStr>(&self, id: S) -> Result<Option<Ref<RemoteFolder>>, ()> { + pub fn get_folder_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteFolder>>, ()> { // TODO: This sync should be removed? if !self.has_pulled_folders() { self.pull_folders()?; @@ -472,8 +472,8 @@ impl RemoteProject { parent_folder: Option<&RemoteFolder>, ) -> Result<Ref<RemoteFolder>, ()> where - N: AsCStr, - D: AsCStr, + N: IntoCStr, + D: IntoCStr, { self.create_folder_with_progress(name, description, parent_folder, NoProgressCallback) } @@ -494,8 +494,8 @@ impl RemoteProject { mut progress: P, ) -> Result<Ref<RemoteFolder>, ()> where - N: AsCStr, - D: AsCStr, + N: IntoCStr, + D: IntoCStr, P: ProgressCallback, { // TODO: This sync should be removed? @@ -529,8 +529,8 @@ impl RemoteProject { pub fn push_folder<I, K, V>(&self, folder: &RemoteFolder, extra_fields: I) -> Result<(), ()> where I: Iterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, { // TODO: This sync should be removed? self.open()?; @@ -598,7 +598,7 @@ impl RemoteProject { /// Get a specific permission in the Project by its id. /// /// NOTE: If group or user permissions have not been pulled, they will be pulled upon calling this. - pub fn get_permission_by_id<S: AsCStr>(&self, id: S) -> Result<Option<Ref<Permission>>, ()> { + pub fn get_permission_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<Permission>>, ()> { // TODO: This sync should be removed? if !self.has_pulled_user_permissions() { self.pull_user_permissions()?; @@ -703,7 +703,7 @@ impl RemoteProject { /// /// * `user_id` - User id /// * `level` - Permission level - pub fn create_user_permission<S: AsCStr>( + pub fn create_user_permission<S: IntoCStr>( &self, user_id: S, level: CollaborationPermissionLevel, @@ -718,7 +718,7 @@ impl RemoteProject { /// * `user_id` - User id /// * `level` - Permission level /// * `progress` - The progress callback to call - pub fn create_user_permission_with_progress<S: AsCStr, F: ProgressCallback>( + pub fn create_user_permission_with_progress<S: IntoCStr, F: ProgressCallback>( &self, user_id: S, level: CollaborationPermissionLevel, @@ -753,8 +753,8 @@ impl RemoteProject { ) -> Result<(), ()> where I: Iterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, { let (keys, values): (Vec<_>, Vec<_>) = extra_fields .into_iter() @@ -788,7 +788,7 @@ impl RemoteProject { /// # Arguments /// /// * `username` - Username of user to check - pub fn can_user_view<S: AsCStr>(&self, username: S) -> bool { + pub fn can_user_view<S: IntoCStr>(&self, username: S) -> bool { let username = username.to_cstr(); unsafe { BNRemoteProjectCanUserView(self.handle.as_ptr(), username.as_ptr()) } } @@ -798,7 +798,7 @@ impl RemoteProject { /// # Arguments /// /// * `username` - Username of user to check - pub fn can_user_edit<S: AsCStr>(&self, username: S) -> bool { + pub fn can_user_edit<S: IntoCStr>(&self, username: S) -> bool { let username = username.to_cstr(); unsafe { BNRemoteProjectCanUserEdit(self.handle.as_ptr(), username.as_ptr()) } } @@ -808,7 +808,7 @@ impl RemoteProject { /// # Arguments /// /// * `username` - Username of user to check - pub fn can_user_admin<S: AsCStr>(&self, username: S) -> bool { + pub fn can_user_admin<S: IntoCStr>(&self, username: S) -> bool { let username = username.to_cstr(); unsafe { BNRemoteProjectCanUserAdmin(self.handle.as_ptr(), username.as_ptr()) } } diff --git a/rust/src/collaboration/remote.rs b/rust/src/collaboration/remote.rs index 4d69873a..baeba412 100644 --- a/rust/src/collaboration/remote.rs +++ b/rust/src/collaboration/remote.rs @@ -10,7 +10,7 @@ use crate::enterprise; use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::project::Project; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; #[repr(transparent)] pub struct Remote { @@ -27,7 +27,7 @@ impl Remote { } /// Create a Remote and add it to the list of known remotes (saved to Settings) - pub fn new<N: AsCStr, A: AsCStr>(name: N, address: A) -> Ref<Self> { + pub fn new<N: IntoCStr, A: IntoCStr>(name: N, address: A) -> Ref<Self> { let name = name.to_cstr(); let address = address.to_cstr(); let result = unsafe { BNCollaborationCreateRemote(name.as_ptr(), address.as_ptr()) }; @@ -163,7 +163,7 @@ impl Remote { } /// Requests an authentication token using a username and password. - pub fn request_authentication_token<U: AsCStr, P: AsCStr>( + pub fn request_authentication_token<U: IntoCStr, P: IntoCStr>( &self, username: U, password: P, @@ -275,7 +275,7 @@ impl Remote { /// Gets a specific project in the Remote by its id. /// /// NOTE: If projects have not been pulled, they will be pulled upon calling this. - pub fn get_project_by_id<S: AsCStr>(&self, id: S) -> Result<Option<Ref<RemoteProject>>, ()> { + pub fn get_project_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteProject>>, ()> { if !self.has_pulled_projects() { self.pull_projects()?; } @@ -288,7 +288,7 @@ impl Remote { /// Gets a specific project in the Remote by its name. /// /// NOTE: If projects have not been pulled, they will be pulled upon calling this. - pub fn get_project_by_name<S: AsCStr>( + pub fn get_project_by_name<S: IntoCStr>( &self, name: S, ) -> Result<Option<Ref<RemoteProject>>, ()> { @@ -331,7 +331,7 @@ impl Remote { /// /// * `name` - Project name /// * `description` - Project description - pub fn create_project<N: AsCStr, D: AsCStr>( + pub fn create_project<N: IntoCStr, D: IntoCStr>( &self, name: N, description: D, @@ -383,8 +383,8 @@ impl Remote { pub fn push_project<I, K, V>(&self, project: &RemoteProject, extra_fields: I) -> Result<(), ()> where I: Iterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, { let (keys, values): (Vec<_>, Vec<_>) = extra_fields .into_iter() @@ -446,7 +446,7 @@ impl Remote { /// /// If groups have not been pulled, they will be pulled upon calling this. /// This function is only available to accounts with admin status on the Remote. - pub fn get_group_by_name<S: AsCStr>(&self, name: S) -> Result<Option<Ref<RemoteGroup>>, ()> { + pub fn get_group_by_name<S: IntoCStr>(&self, name: S) -> Result<Option<Ref<RemoteGroup>>, ()> { if !self.has_pulled_groups() { self.pull_groups()?; } @@ -462,7 +462,7 @@ impl Remote { /// # Arguments /// /// * `prefix` - Prefix of name for groups - pub fn search_groups<S: AsCStr>( + pub fn search_groups<S: IntoCStr>( &self, prefix: S, ) -> Result<(Array<GroupId>, Array<BnString>), ()> { @@ -526,9 +526,9 @@ impl Remote { /// * `usernames` - List of usernames of users in the group pub fn create_group<N, I>(&self, name: N, usernames: I) -> Result<Ref<RemoteGroup>, ()> where - N: AsCStr, + N: IntoCStr, I: IntoIterator, - I::Item: AsCStr, + I::Item: IntoCStr, { let name = name.to_cstr(); let usernames: Vec<_> = usernames.into_iter().map(|s| s.to_cstr()).collect(); @@ -557,8 +557,8 @@ impl Remote { pub fn push_group<I, K, V>(&self, group: &RemoteGroup, extra_fields: I) -> Result<(), ()> where I: IntoIterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, { let (keys, values): (Vec<_>, Vec<_>) = extra_fields .into_iter() @@ -617,7 +617,7 @@ impl Remote { /// # Arguments /// /// * `id` - The identifier of the user to retrieve. - pub fn get_user_by_id<S: AsCStr>(&self, id: S) -> Result<Option<Ref<RemoteUser>>, ()> { + pub fn get_user_by_id<S: IntoCStr>(&self, id: S) -> Result<Option<Ref<RemoteUser>>, ()> { if !self.has_pulled_users() { self.pull_users()?; } @@ -635,7 +635,7 @@ impl Remote { /// # Arguments /// /// * `username` - The username of the user to retrieve. - pub fn get_user_by_username<S: AsCStr>( + pub fn get_user_by_username<S: IntoCStr>( &self, username: S, ) -> Result<Option<Ref<RemoteUser>>, ()> { @@ -665,7 +665,7 @@ impl Remote { /// # Arguments /// /// * `prefix` - The prefix to search for in usernames. - pub fn search_users<S: AsCStr>( + pub fn search_users<S: IntoCStr>( &self, prefix: S, ) -> Result<(Array<BnString>, Array<BnString>), ()> { @@ -730,7 +730,7 @@ impl Remote { /// # Arguments /// /// * Various details about the new user to be created. - pub fn create_user<U: AsCStr, E: AsCStr, P: AsCStr>( + pub fn create_user<U: IntoCStr, E: IntoCStr, P: IntoCStr>( &self, username: U, email: E, @@ -772,8 +772,8 @@ impl Remote { pub fn push_user<I, K, V>(&self, user: &RemoteUser, extra_fields: I) -> Result<(), ()> where I: Iterator<Item = (K, V)>, - K: AsCStr, - V: AsCStr, + K: IntoCStr, + V: IntoCStr, { let (keys, values): (Vec<_>, Vec<_>) = extra_fields .into_iter() diff --git a/rust/src/collaboration/snapshot.rs b/rust/src/collaboration/snapshot.rs index 6e1dfb89..c8256608 100644 --- a/rust/src/collaboration/snapshot.rs +++ b/rust/src/collaboration/snapshot.rs @@ -8,7 +8,7 @@ use crate::collaboration::undo::{RemoteUndoEntry, RemoteUndoEntryId}; use crate::database::snapshot::Snapshot; use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; use binaryninjacore_sys::*; // TODO: RemoteSnapshotId ? @@ -226,7 +226,7 @@ impl RemoteSnapshot { } /// Create a new Undo Entry in this snapshot. - pub fn create_undo_entry<S: AsCStr>( + pub fn create_undo_entry<S: IntoCStr>( &self, parent: Option<u64>, data: S, diff --git a/rust/src/collaboration/sync.rs b/rust/src/collaboration/sync.rs index 5afb8923..b1b26982 100644 --- a/rust/src/collaboration/sync.rs +++ b/rust/src/collaboration/sync.rs @@ -11,7 +11,7 @@ use crate::file_metadata::FileMetadata; use crate::progress::{NoProgressCallback, ProgressCallback}; use crate::project::file::ProjectFile; use crate::rc::Ref; -use crate::string::{raw_to_string, AsCStr, BnString}; +use crate::string::{raw_to_string, BnString, IntoCStr}; use crate::type_archive::{TypeArchive, TypeArchiveMergeConflict}; // TODO: PathBuf @@ -43,7 +43,7 @@ pub fn default_file_path(file: &RemoteFile) -> Result<BnString, ()> { /// /// * `file` - Remote File to download and open /// * `db_path` - File path for saved database -pub fn download_file<S: AsCStr>(file: &RemoteFile, db_path: S) -> Result<Ref<FileMetadata>, ()> { +pub fn download_file<S: IntoCStr>(file: &RemoteFile, db_path: S) -> Result<Ref<FileMetadata>, ()> { download_file_with_progress(file, db_path, NoProgressCallback) } @@ -54,7 +54,7 @@ pub fn download_file<S: AsCStr>(file: &RemoteFile, db_path: S) -> Result<Ref<Fil /// * `file` - Remote File to download and open /// * `db_path` - File path for saved database /// * `progress` - Function to call for progress updates -pub fn download_file_with_progress<S: AsCStr, F: ProgressCallback>( +pub fn download_file_with_progress<S: IntoCStr, F: ProgressCallback>( file: &RemoteFile, db_path: S, mut progress: F, @@ -220,7 +220,7 @@ pub fn get_local_snapshot_for_remote( pub fn download_database<S>(file: &RemoteFile, location: S, force: bool) -> Result<(), ()> where - S: AsCStr, + S: IntoCStr, { download_database_with_progress(file, location, force, NoProgressCallback) } @@ -232,7 +232,7 @@ pub fn download_database_with_progress<S, F>( mut progress: F, ) -> Result<(), ()> where - S: AsCStr, + S: IntoCStr, F: ProgressCallback, { let db_path = location.to_cstr(); @@ -475,7 +475,7 @@ pub fn get_snapshot_author( /// * `database` - Parent database /// * `snapshot` - Snapshot to edit /// * `author` - Target author -pub fn set_snapshot_author<S: AsCStr>( +pub fn set_snapshot_author<S: IntoCStr>( database: &Database, snapshot: &Snapshot, author: S, @@ -650,7 +650,7 @@ pub fn get_remote_file_for_local_type_archive(database: &TypeArchive) -> Option< } /// Get the remote snapshot associated with a local snapshot (if it exists) in a Type Archive -pub fn get_remote_snapshot_from_local_type_archive<S: AsCStr>( +pub fn get_remote_snapshot_from_local_type_archive<S: IntoCStr>( type_archive: &TypeArchive, snapshot_id: S, ) -> Option<Ref<RemoteSnapshot>> { @@ -679,7 +679,7 @@ pub fn get_local_snapshot_from_remote_type_archive( } /// Test if a snapshot is ignored from the archive -pub fn is_type_archive_snapshot_ignored<S: AsCStr>( +pub fn is_type_archive_snapshot_ignored<S: IntoCStr>( type_archive: &TypeArchive, snapshot_id: S, ) -> bool { @@ -694,7 +694,7 @@ pub fn is_type_archive_snapshot_ignored<S: AsCStr>( /// Download a type archive from its remote, saving all snapshots to an archive in the /// specified `location`. Returns a [`TypeArchive`] for using later. -pub fn download_type_archive<S: AsCStr>( +pub fn download_type_archive<S: IntoCStr>( file: &RemoteFile, location: S, ) -> Result<Option<Ref<TypeArchive>>, ()> { @@ -703,7 +703,7 @@ pub fn download_type_archive<S: AsCStr>( /// Download a type archive from its remote, saving all snapshots to an archive in the /// specified `location`. Returns a [`TypeArchive`] for using later. -pub fn download_type_archive_with_progress<S: AsCStr, F: ProgressCallback>( +pub fn download_type_archive_with_progress<S: IntoCStr, F: ProgressCallback>( file: &RemoteFile, location: S, mut progress: F, diff --git a/rust/src/collaboration/user.rs b/rust/src/collaboration/user.rs index d4aea2c5..6b490942 100644 --- a/rust/src/collaboration/user.rs +++ b/rust/src/collaboration/user.rs @@ -3,7 +3,7 @@ use binaryninjacore_sys::*; use std::ptr::NonNull; use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCountable}; -use crate::string::{AsCStr, BnString}; +use crate::string::{BnString, IntoCStr}; #[repr(transparent)] pub struct RemoteUser { @@ -48,7 +48,7 @@ impl RemoteUser { } /// Set user's username. You will need to push the user to update the Remote - pub fn set_username<U: AsCStr>(&self, username: U) -> Result<(), ()> { + pub fn set_username<U: IntoCStr>(&self, username: U) -> Result<(), ()> { let username = username.to_cstr(); let result = unsafe { BNCollaborationUserSetUsername(self.handle.as_ptr(), username.as_ptr()) }; @@ -67,7 +67,7 @@ impl RemoteUser { } /// Set user's email. You will need to push the user to update the Remote - pub fn set_email<U: AsCStr>(&self, email: U) -> Result<(), ()> { + pub fn set_email<U: IntoCStr>(&self, email: U) -> Result<(), ()> { let username = email.to_cstr(); let result = unsafe { BNCollaborationUserSetEmail(self.handle.as_ptr(), username.as_ptr()) }; |
