Expand description
This crate allows asynchronous value exchanges between two endpoints.
Conceptually this is similar to having two channels, each with capacity 1.
§Example
Create an exchange between a client A and a server B where A sends
u32
values to B and B acknowledges each value with a bool
, true
if the value is odd and false
otherwise.
let (mut a, mut b) = scambio::exchange();
let client = async move {
for i in 0 .. 10u32 {
assert!(a.send(i).await.is_ok());
assert_eq!(Some(i % 2 == 1), a.receive().await)
}
};
let server = async move {
while let Some(i) = b.receive().await {
assert!(b.send(i % 2 == 1).await.is_ok())
}
};
assert_eq!(futures::join!(client, server), ((), ()));
Structs§
- An exchange endpoint for value transfers.
- An exchange endpoint for value transfers.
Enums§
- Possible errors when exchanging data.
Functions§
- Create a new exchange between
Left
andRight
.