suck

Crates.iosuck
lib.rssuck
version0.0.2
created_at2025-09-02 14:37:54.031091+00
updated_at2025-09-04 14:23:44.395566+00
descriptionSuck data up through a channel
homepagehttps://github.com/callumio/suck
repositoryhttps://github.com/callumio/suck
max_upload_size
id1821221
size39,095
Callum Leslie (callumio)

documentation

https://docs.rs/suck

README

suck

Suck data up through a channel

Crates.io Github Actions Documentation License

[!WARNING]
This is unstable, untested and subject to change - use at your own risk.

Features

  • Pull-based communication: Consumers request values on-demand
  • Contextual values: Designed for current state rather than event streams
  • Flexible sources: Support both static values and dynamic closures

Installation

Add this to your Cargo.toml:

[dependencies]
suck = "*"

Quick Start

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(())
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Commit count: 17

cargo fmt