global-channel

Crates.ioglobal-channel
lib.rsglobal-channel
version0.2.0
created_at2025-01-25 19:46:10.709882+00
updated_at2025-01-25 20:04:07.51457+00
descriptionSimple global channels.
homepage
repositoryhttps://www.github.com/alexdesander/global-channel
max_upload_size
id1530815
size19,820
Alexdesander (alexdesander)

documentation

README

global-channel

global-channel is a lightweight Rust crate that provides a simple way to define and use global, static channels for message passing. It supports both bounded and unbounded channels, powered by crossbeam-channel.

Features

  • Define static, global channels with minimal boilerplate.
  • Bounded and unbounded channels.
  • Safe initialization using std::sync::Once.
  • Highly performant with crossbeam-channel.

Usage

Create and use a global channel with the global_channel! macro:

use global_channel::global_channel;

global_channel!(my_channel, Some(10), u32); // Bounded channel with capacity 10

fn main() {
    let tx = my_channel_tx();
    let rx = my_channel_rx();

    tx.send(42).unwrap();
    println!("Received: {}", rx.recv().unwrap());
}

For an unbounded channel:

global_channel!(unbounded_channel, None, String);

Basic Example

use global_channel::global_channel;

global_channel!(example_channel, None, i32);

fn main() {
    let tx = example_channel_tx();
    let rx = example_channel_rx();

    tx.send(100).unwrap();
    assert_eq!(rx.recv().unwrap(), 100);
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 0

cargo fmt