-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding into_raw() and from_raw() methods
See issue #28.
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#![cfg(not(loom))] | ||
|
||
use oneshot::{channel, Receiver, Sender}; | ||
|
||
#[test] | ||
fn test_raw_sender() { | ||
let (sender, receiver) = channel::<u32>(); | ||
let raw = sender.into_raw(); | ||
let recreated = unsafe { Sender::<u32>::from_raw(raw) }; | ||
recreated | ||
.send(100) | ||
.unwrap_or_else(|e| panic!("error sending after into_raw/from_raw roundtrip: {e}")); | ||
assert_eq!(receiver.try_recv(), Ok(100)) | ||
} | ||
|
||
#[test] | ||
fn test_raw_receiver() { | ||
let (sender, receiver) = channel::<u32>(); | ||
let raw = receiver.into_raw(); | ||
sender.send(100).unwrap(); | ||
let recreated = unsafe { Receiver::<u32>::from_raw(raw) }; | ||
assert_eq!( | ||
recreated | ||
.try_recv() | ||
.unwrap_or_else(|e| panic!("error receiving after into_raw/from_raw roundtrip: {e}")), | ||
100 | ||
) | ||
} | ||
|
||
#[test] | ||
fn test_raw_sender_and_receiver() { | ||
let (sender, receiver) = channel::<u32>(); | ||
let raw_receiver = receiver.into_raw(); | ||
let raw_sender = sender.into_raw(); | ||
|
||
let recreated_sender = unsafe { Sender::<u32>::from_raw(raw_sender) }; | ||
recreated_sender.send(100).unwrap(); | ||
|
||
let recreated_receiver = unsafe { Receiver::<u32>::from_raw(raw_receiver) }; | ||
assert_eq!( | ||
recreated_receiver | ||
.try_recv() | ||
.unwrap_or_else(|e| panic!("error receiving after into_raw/from_raw roundtrip: {e}")), | ||
100 | ||
) | ||
} |