Skip to content

Commit

Permalink
update: changed to use Box::leak and NonNull::from for avoiding unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk committed Dec 14, 2024
1 parent 773270e commit 4134135
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/errs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ impl Err {
R: fmt::Debug + Send + Sync + 'static,
{
let boxed = Box::new(ReasonContainer::<R>::new(reason));
let ptr: ptr::NonNull<ReasonContainer> =
unsafe { ptr::NonNull::new_unchecked(Box::into_raw(boxed)).cast::<ReasonContainer>() };
let ptr = ptr::NonNull::from(Box::leak(boxed)).cast::<ReasonContainer>();
Self {
reason_container: ptr,
source: Box::new(NoSource {}),
Expand Down Expand Up @@ -65,8 +64,7 @@ impl Err {
E: error::Error + Send + Sync + 'static,
{
let boxed = Box::new(ReasonContainer::<R>::new(reason));
let ptr: ptr::NonNull<ReasonContainer> =
unsafe { ptr::NonNull::new_unchecked(Box::into_raw(boxed)).cast::<ReasonContainer>() };
let ptr = ptr::NonNull::from(Box::leak(boxed)).cast::<ReasonContainer>();
Self {
reason_container: ptr,
source: Box::new(source),
Expand Down

0 comments on commit 4134135

Please sign in to comment.