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/background_task.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'rust/src/background_task.rs') diff --git a/rust/src/background_task.rs b/rust/src/background_task.rs index c9059aca..95bdda0b 100644 --- a/rust/src/background_task.rs +++ b/rust/src/background_task.rs @@ -45,7 +45,7 @@ impl BackgroundTask { pub fn new(initial_text: S, can_cancel: bool) -> Ref { let text = initial_text.to_cstr(); - let handle = unsafe { BNBeginBackgroundTask(text.as_ref().as_ptr() as *mut _, can_cancel) }; + let handle = unsafe { BNBeginBackgroundTask(text.as_ptr(), can_cancel) }; // We should always be returned a valid task. assert!(!handle.is_null()); unsafe { Ref::new(Self { handle }) } @@ -77,9 +77,7 @@ impl BackgroundTask { pub fn set_progress_text(&self, text: S) { let progress_text = text.to_cstr(); - unsafe { - BNSetBackgroundTaskProgressText(self.handle, progress_text.as_ref().as_ptr() as *mut _) - } + unsafe { BNSetBackgroundTaskProgressText(self.handle, progress_text.as_ptr()) } } pub fn running_tasks() -> Array { -- cgit v1.3.1