https://github.com/agersant/squeak
Rust library to facilitate event-driven programming.
https://github.com/agersant/squeak
rust
Last synced: about 1 year ago
JSON representation
Rust library to facilitate event-driven programming.
- Host: GitHub
- URL: https://github.com/agersant/squeak
- Owner: agersant
- License: apache-2.0
- Created: 2022-12-03T23:36:29.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-26T20:57:17.000Z (over 2 years ago)
- Last Synced: 2025-06-04T01:17:20.660Z (about 1 year ago)
- Topics: rust
- Language: Rust
- Homepage:
- Size: 31.3 KB
- Stars: 77
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Squeak
[![build_badge]][build_link] [![crates.io_badge]][crates.io_link] [![docs_badge]][docs_link]
[build_badge]: https://img.shields.io/github/actions/workflow/status/agersant/squeak/CI.yml?branch=master
[build_link]: https://github.com/agersant/squeak/actions/workflows/CI.yml?query=branch%3A+branch%3Amaster++
[crates.io_badge]: https://img.shields.io/badge/crates.io-squeak-green
[crates.io_link]: https://crates.io/crates/squeak
[docs_badge]: https://img.shields.io/badge/docs.rs-squeak-blue
[docs_link]: https://docs.rs/squeak/latest/squeak/
Squeak is a zero-dependency Rust library to facilitate event-driven programming.
# Examples
```rust
use squeak::{Delegate, Response};
let on_damage_received = Delegate::new();
on_damage_received.subscribe(|amount| {
println!("Received {amount} damage");
Response::StaySubscribed
});
on_damage_received.broadcast(16); // Prints "Received 16 damage"
on_damage_received.broadcast(14); // Prints "Received 14 damage"
on_damage_received.broadcast(28); // Prints "Received 28 damage"
```
```rust
use squeak::{Observable, Response};
let mut health = Observable::new(100);
health.subscribe(|updated_health| {
println!("Health is now {updated_health}");
Response::StaySubscribed
});
health.mutate(|h| *h -= 10); // Prints "Health is now 90"
health.mutate(|h| *h -= 5); // Prints "Health is now 85"
health.mutate(|h| *h += 25); // Prints "Health is now 110"
```