📦🚀 A crate that allows for easy and fast communication between processes, threads and systems. https://docs.rs/channels
  • Rust 96.3%
  • Python 1.6%
  • Nix 1%
  • Just 0.6%
  • Shell 0.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
threadexio 31f5db58d0
Some checks failed
CI / check (push) Has been cancelled
CI / Test on macos-latest (push) Has been cancelled
CI / Test on ubuntu-latest (push) Has been cancelled
CI / Test on windows-latest (push) Has been cancelled
CI / doc (push) Has been cancelled
CI / miri (s390x-unknown-linux-gnu) (push) Has been cancelled
CI / miri (x86_64-unknown-linux-gnu) (push) Has been cancelled
Docs / build-docs (push) Has been cancelled
Docs / deploy (push) Has been cancelled
bump crate versions
2024-10-10 15:56:59 +03:00
.github/workflows ci: run miri on both little and big endian targets 2024-09-04 13:35:24 +03:00
assets add blurred gradient as background of repo banner 2024-05-04 14:02:19 +03:00
benches fix: recv benchmarks 2024-09-04 11:04:10 +03:00
bin chore: install latest rust version in flake.nix 2024-08-20 12:56:51 +03:00
channels bump crate versions 2024-10-10 15:56:59 +03:00
channels-io bump crate versions 2024-10-10 15:56:59 +03:00
channels-macros chore: clean up all Cargo.toml manifests 2024-03-25 14:42:03 +02:00
channels-packet bump crate versions 2024-10-10 15:56:59 +03:00
channels-serdes fix: unused import errors when building standalone 2024-09-08 20:40:05 +03:00
examples fix: embedded example 2024-06-07 10:36:37 +03:00
perf perf: add benchmarks for channels-packet 2024-09-05 11:49:01 +03:00
spec docs: update protocol spec 2024-09-04 11:25:18 +03:00
stress-tests chore: print stats from receiver in stress-tests 2024-08-19 15:34:28 +03:00
tests-integration feat: use fixed 32-bit length for frames 2024-09-04 10:53:49 +03:00
.editorconfig docs: rework art export 2023-12-27 21:23:37 +02:00
.gitignore chore: add scripts to record with perf 2024-09-02 01:36:26 +03:00
Cargo.toml perf: add perf binaries 2024-08-20 14:57:27 +03:00
clippy.toml fix: ignore duplicate versions of miniz_oxide 2024-08-20 14:25:53 +03:00
default.nix chore: add flake.nix 2023-07-27 20:05:57 +03:00
flake.lock chore: install latest rust version in flake.nix 2024-08-20 12:56:51 +03:00
flake.nix chore: install cargo-flamegraph in flake 2024-08-20 15:16:59 +03:00
justfile chore: add scripts to record with perf 2024-09-02 01:36:26 +03:00
LICENSE chore: reverse license, readme symlinks 2023-08-08 14:12:54 +03:00
README.md bump crate versions 2024-10-10 15:56:59 +03:00
rust-toolchain.toml chore: add rust-toolchain.toml 2023-07-27 19:41:35 +03:00
rustfmt.toml docs: add logo and update style 2023-07-18 13:14:38 +03:00
shell.nix chore: add flake.nix 2023-07-27 20:05:57 +03:00

logo

Easy and fast communication between processes, threads and systems.

license-badge tests-badge version-badge docs-badge downloads-badge


Sender/Receiver types for communicating with a channel-like API across generic IO streams. It takes the burden on serializing, deserializing and transporting data off your back and let's you focus on the important logic of your project.

Contents

Examples

[dependencies.channels]
version = "0.13"
features = ["full"]
use tokio::net::TcpStream;

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
enum Message {
    Ping,
    Pong
}

#[tokio::main]
async fn main() {
    let stream = TcpStream::connect("127.0.0.1:8080").await.unwrap();
    let (r, w) = stream.into_split();
    let (mut tx, mut rx) = channels::channel::<Message, _, _>(r, w);

    loop {
        match rx.recv().await.unwrap() {
            Message::Ping => {
                println!("pinged!");
                tx.send(Message::Pong).await.unwrap();
            }
            Message::Pong => {
                println!("ponged!");
            }
        }
    }
}

For more, see: examples/

Features

Flag Description
aead Encrypt and authenticate data with ring::aead.
bincode Serialize/Deserialize data with bincode. (Enabled by default)
borsh Serialize/Deserialize data with borsh.
cbor Serialize/Deserialize data with ciborium.
core2 Support for core2::io::{Read, Write}.
crc Validate data with a CRC checksum.
deflate Compress data with DEFLATE.
embedded-io Support for embedded_io::{Read, Write}.
full-io Enable support for all of the IO traits.
full-serdes Enable features: aead, bincode, borsh, cbor, crc, deflate, hmac, json.
futures Support for futures::io::{AsyncRead, AsyncWrite}.
hmac Authenticate data with a HMAC using ring::hmac.
json Serialize/Deserialize data with serde_json.
smol Support for smol::io::{AsyncRead, AsyncWrite}.
statistics Collect IO metrics such as total bytes sent/received. See: Statistics.
std Support for std::io::{Read, Write}. If disabled also makes the crate no_std. (Enabled by default)
tokio Support for tokio::io::{AsyncRead, AsyncWrite}.

No two features of the crate are mutually exclusive. Instead, everything is implemented in a way to be infinitely extensible. This means, that even if you have other IO traits or another way to serialize or deserialize data, you can either add support for them directly in your own project by using the rich type system.

How it works

Channels implements a communication protocol that allows sending and receiving data in frames. The main API of the crate is intended to work over IO traits. However, if desired, the logic of the underlying protocol is available standalone without coupling it to the usage of any IO traits. It works over any stream synchronous or asynchronous with first class support for following IO traits:

Support for each IO trait can be enabled via the corresponding feature flag. See: Features. You can read more about how the underlying communication protocol works here.

License