[−][src]Crate scambio
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
Left | An exchange endpoint for value transfers. |
Right | An exchange endpoint for value transfers. |
Enums
Error | Possible errors when exchanging data. |
Functions
exchange | Create a new exchange between |