From 41341356da5858ff6f4342ecfa906852ae4d3719 Mon Sep 17 00:00:00 2001 From: sttk Date: Sat, 14 Dec 2024 19:45:07 +0900 Subject: [PATCH] update: changed to use Box::leak and NonNull::from for avoiding unsafe --- src/errs.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/errs.rs b/src/errs.rs index 22f8316..340f82d 100644 --- a/src/errs.rs +++ b/src/errs.rs @@ -35,8 +35,7 @@ impl Err { R: fmt::Debug + Send + Sync + 'static, { let boxed = Box::new(ReasonContainer::::new(reason)); - let ptr: ptr::NonNull = - unsafe { ptr::NonNull::new_unchecked(Box::into_raw(boxed)).cast::() }; + let ptr = ptr::NonNull::from(Box::leak(boxed)).cast::(); Self { reason_container: ptr, source: Box::new(NoSource {}), @@ -65,8 +64,7 @@ impl Err { E: error::Error + Send + Sync + 'static, { let boxed = Box::new(ReasonContainer::::new(reason)); - let ptr: ptr::NonNull = - unsafe { ptr::NonNull::new_unchecked(Box::into_raw(boxed)).cast::() }; + let ptr = ptr::NonNull::from(Box::leak(boxed)).cast::(); Self { reason_container: ptr, source: Box::new(source),