Skip to content

Commit

Permalink
Remove use of "unsafe" during channel creation
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwuelker committed May 8, 2024
1 parent 00e8e39 commit 3d3b824
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,7 @@ pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
// Allocate the channel on the heap and get the pointer.
// The last endpoint of the channel to be alive is responsible for freeing the channel
// and dropping any object that might have been written to it.

let channel_ptr = Box::into_raw(Box::new(Channel::new()));

// SAFETY: `channel_ptr` came from a Box and thus is not null
let channel_ptr = unsafe { NonNull::new_unchecked(channel_ptr) };
let channel_ptr = NonNull::from(Box::leak(Box::new(Channel::new())));

(
Sender {
Expand Down

0 comments on commit 3d3b824

Please sign in to comment.