| Crates.io | shigunaru |
| lib.rs | shigunaru |
| version | 0.0.1 |
| created_at | 2025-05-11 07:43:39.05353+00 |
| updated_at | 2025-05-11 07:43:39.05353+00 |
| description | A lightweight reactive signals library in Rust |
| homepage | https://github.com/tsukuricase/shigunaru |
| repository | https://github.com/tsukuricase/shigunaru |
| max_upload_size | |
| id | 1669167 |
| size | 37,976 |
A lightweight reactive signals library implemented in Rust.
Add this to your Cargo.toml:
[dependencies]
shigunaru = "0.1.0"
use shigunaru::{Signal, create_computed, create_effect};
// Create a signal with initial value
let counter = Signal::new(0);
// Use it directly
counter.set(5);
let value = *counter.get().borrow();
// Subscribe to changes
let counter_effect = counter.clone();
create_effect(
move || {
println!("Counter changed: {}", *counter_effect.get().borrow());
},
&counter,
);
// Change the signal value - will trigger the effect
counter.set(10);
Computed signals derive their values from other signals and automatically update when dependencies change:
use shigunaru::{Signal, create_computed};
// Base signal
let count = Signal::new(1);
// Create a computed signal
let count_for_computed = count.clone();
let doubled = create_computed(move || {
*count_for_computed.get().borrow() * 2
});
// Initial computed value
assert_eq!(doubled.value(), 2);
// Update the source signal
count.set(5);
// Computed value automatically updates
assert_eq!(doubled.value(), 10);
See the examples directory for more usage examples:
counter.rs - Basic counter with computed valuesRun an example with:
cargo run --example counter
shigunaru/
├── src/
│ ├── lib.rs # Main API exports
│ ├── signal.rs # Signal implementation
│ ├── computed.rs # Computed signals
│ ├── effect.rs # Effect system
│ ├── registry.rs # Dependency tracking
│ └── tests/ # Unit tests
├── examples/ # Usage examples
└── tests/ # Integration tests
MIT