| Crates.io | global-channel |
| lib.rs | global-channel |
| version | 0.2.0 |
| created_at | 2025-01-25 19:46:10.709882+00 |
| updated_at | 2025-01-25 20:04:07.51457+00 |
| description | Simple global channels. |
| homepage | |
| repository | https://www.github.com/alexdesander/global-channel |
| max_upload_size | |
| id | 1530815 |
| size | 19,820 |
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.
std::sync::Once.crossbeam-channel.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);
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);
}
Licensed under either of
at your option.
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.