mirror of
https://github.com/callumio/suck.git
synced 2025-12-17 03:29:21 +00:00
docs: populate README
This commit is contained in:
parent
bb5827ead1
commit
33f6d33a15
1 changed files with 72 additions and 0 deletions
72
README.md
72
README.md
|
|
@ -0,0 +1,72 @@
|
||||||
|
# suck
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
|
||||||
|
[](https://crates.io/crates/suck)
|
||||||
|
[](https://github.com/callumio/suck/actions?workflow=ci)
|
||||||
|
[](https://docs.rs/suck)
|
||||||
|
[](LICENSE)
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
Suck data up through a channel
|
||||||
|
|
||||||
|
## 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`:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[dependencies]
|
||||||
|
suck = "*"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use suck::SuckPair;
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
// Create a pair
|
||||||
|
let (sucker, sourcer) = SuckPair::<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](LICENSE) file
|
||||||
|
for details.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue