summaryrefslogtreecommitdiff
path: root/rust/src/collaboration/file.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-04 19:47:55 -0400
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-12 17:45:24 -0400
commit788a8b7091bbdde77817030e0836d7a7a786fd99 (patch)
tree40e8f8d3c870788259a5acb5d14995cdc1656979 /rust/src/collaboration/file.rs
parenta826c589dfc10c542deba7ca3343a462e02d6bde (diff)
[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.
Diffstat (limited to 'rust/src/collaboration/file.rs')
-rw-r--r--rust/src/collaboration/file.rs35
1 files changed, 8 insertions, 27 deletions
diff --git a/rust/src/collaboration/file.rs b/rust/src/collaboration/file.rs
index 2089fbb7..251b4f7d 100644
--- a/rust/src/collaboration/file.rs
+++ b/rust/src/collaboration/file.rs
@@ -1,4 +1,4 @@
-use std::ffi::{c_char, c_void};
+use std::ffi::c_void;
use std::fmt::{Debug, Formatter};
use std::ptr::NonNull;
use std::time::SystemTime;
@@ -96,12 +96,7 @@ impl RemoteFile {
pub fn set_metadata<S: AsCStr>(&self, folder: S) -> Result<(), ()> {
let folder_raw = folder.to_cstr();
- let success = unsafe {
- BNRemoteFileSetMetadata(
- self.handle.as_ptr(),
- folder_raw.as_ref().as_ptr() as *const c_char,
- )
- };
+ let success = unsafe { BNRemoteFileSetMetadata(self.handle.as_ptr(), folder_raw.as_ptr()) };
success.then_some(()).ok_or(())
}
@@ -192,12 +187,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<(), ()> {
let name = name.to_cstr();
- let success = unsafe {
- BNRemoteFileSetName(
- self.handle.as_ptr(),
- name.as_ref().as_ptr() as *const c_char,
- )
- };
+ let success = unsafe { BNRemoteFileSetName(self.handle.as_ptr(), name.as_ptr()) };
success.then_some(()).ok_or(())
}
@@ -211,12 +201,8 @@ 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<(), ()> {
let description = description.to_cstr();
- let success = unsafe {
- BNRemoteFileSetDescription(
- self.handle.as_ptr(),
- description.as_ref().as_ptr() as *const c_char,
- )
- };
+ let success =
+ unsafe { BNRemoteFileSetDescription(self.handle.as_ptr(), description.as_ptr()) };
success.then_some(()).ok_or(())
}
@@ -269,9 +255,7 @@ impl RemoteFile {
self.pull_snapshots()?;
}
let id = id.to_cstr();
- let result = unsafe {
- BNRemoteFileGetSnapshotById(self.handle.as_ptr(), id.as_ref().as_ptr() as *const c_char)
- };
+ let result = unsafe { BNRemoteFileGetSnapshotById(self.handle.as_ptr(), id.as_ptr()) };
Ok(NonNull::new(result).map(|handle| unsafe { RemoteSnapshot::ref_from_raw(handle) }))
}
@@ -350,14 +334,11 @@ impl RemoteFile {
{
let name = name.to_cstr();
let parent_ids: Vec<_> = parent_ids.into_iter().map(|id| id.to_cstr()).collect();
- let mut parent_ids_raw: Vec<_> = parent_ids
- .iter()
- .map(|x| x.as_ref().as_ptr() as *const c_char)
- .collect();
+ let mut parent_ids_raw: Vec<_> = parent_ids.iter().map(|x| x.as_ptr()).collect();
let result = unsafe {
BNRemoteFileCreateSnapshot(
self.handle.as_ptr(),
- name.as_ref().as_ptr() as *const c_char,
+ name.as_ptr(),
contents.as_mut_ptr(),
contents.len(),
analysis_cache_contexts.as_mut_ptr(),