Crates.io | suck |
lib.rs | suck |
version | 0.0.2 |
created_at | 2025-09-02 14:37:54.031091+00 |
updated_at | 2025-09-04 14:23:44.395566+00 |
description | Suck data up through a channel |
homepage | https://github.com/callumio/suck |
repository | https://github.com/callumio/suck |
max_upload_size | |
id | 1821221 |
size | 39,095 |
Suck data up through a channel
[!WARNING]
This is unstable, untested and subject to change - use at your own risk.
Add this to your Cargo.toml
:
[dependencies]
suck = "*"
use suck::sync::StdSuck;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a pair (using default std backend)
let (sucker, sourcer) = StdSuck::<i32>::pair();
// Start producer in a thread
let producer = std::thread::spawn(move || {
// Set a static value
sourcer.set_static(42).unwrap();
// Or set a dynamic closure
sourcer.set(|| {
// Generate fresh values each time
42 * 2
}).unwrap();
// Run the producer loop
sourcer.run().unwrap();
});
// Consumer pulls values
let value = sucker.get()?;
println!("Got value: {}", value);
// Clean up
sucker.close()?;
producer.join().unwrap();
Ok(())
}
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.