From c5f962b3fe69b746154ebe97a70c44d96bfd3f56 Mon Sep 17 00:00:00 2001 From: Boxy Date: Thu, 13 Mar 2025 15:45:03 +0000 Subject: [PATCH] Remove object lifetime cast --- src/yield_now.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/yield_now.rs b/src/yield_now.rs index 28a60a47..96ab512a 100644 --- a/src/yield_now.rs +++ b/src/yield_now.rs @@ -30,7 +30,11 @@ pub fn yield_with(resource: &T) { return resource.yield_back(cancel); } - let r = resource as &dyn EventSource as *const _ as *mut _; + let r = unsafe { + std::mem::transmute::<*const (dyn EventSource + '_), *mut (dyn EventSource + 'static)>( + resource as &dyn EventSource, + ) + }; let es = EventSubscriber::new(r); co_yield_with(es); @@ -45,13 +49,21 @@ pub fn yield_with_io(resource: &T, is_coroutine: bool) { yield_with(resource); #[cfg(not(feature = "io_cancel"))] { - let r = resource as &dyn EventSource as *const _ as *mut _; + let r = unsafe { + std::mem::transmute::<*const (dyn EventSource + '_), *mut (dyn EventSource + 'static)>( + resource as &dyn EventSource, + ) + }; let es = EventSubscriber::new(r); co_yield_with(es); } } else { // for thread is only park the thread - let r = resource as &dyn EventSource as *const _ as *mut _; + let r = unsafe { + std::mem::transmute::<*const (dyn EventSource + '_), *mut (dyn EventSource + 'static)>( + resource as &dyn EventSource, + ) + }; let es = EventSubscriber::new(r); crate::io::thread::PROXY_CO_SENDER.with(|tx| { tx.send(es).unwrap();