1 unstable release

0.2.0 Jan 25, 2025
0.1.0 Jan 25, 2025

#369 in Concurrency

Download history 90/week @ 2025-01-19 118/week @ 2025-01-26 20/week @ 2025-02-02

228 downloads per month

MIT/Apache

8KB
58 lines

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.

Dependencies

~360KB