generic-session-types

Crates.iogeneric-session-types
lib.rsgeneric-session-types
version0.1.1
sourcesrc
created_at2022-11-26 07:07:07.790453
updated_at2023-05-18 12:46:10.018533
descriptionGeneric session types in Rust for async send recv channel
homepagehttps://github.com/chnlkw/generic-session-types
repositoryhttps://github.com/chnlkw/generic-session-types
max_upload_size
id723147
size22,551
Kaiwei Li (chnlkw)

documentation

README

generic-session-types

Generic session types in Rust for async send recv channel

Prerequisites

rustup default nightly

Usage

Add dependency to Cargo.toml

[dependencies]
generic-session-types = "0.1.0"

Example


use generic_session_types::*;

type P2 = Send<String, Recv<usize, Close>>;

#[tokio::test]
async fn test_tokio_mpsc_channel2_dyn_message() {
    let (client, server) = mpsc::channel::<P2, BoxAnyRepr>(10);
    let msg = String::from("asdfsdfds");
    let h1: JoinHandle<Result<usize, Error>> = tokio::spawn(async move {
        send!(client, msg);
        recv!(client, r);
        close!(client);
        Ok(r)
    });
    let h2: JoinHandle<Result<(), Error>> = tokio::spawn(async move {
        let (s, c) = server.recv().await?;
        let c = c.send(s.len()).await?;
        c.close().await?;
        Ok(())
    });
    let r0 = h1.await.unwrap();
    let r1 = h2.await.unwrap();
    assert_eq!(r0, Ok(9));
    assert_eq!(r1, Ok(()));
}
  • See more cases in tests

References

Commit count: 34

cargo fmt