Crates.io | bloc |
lib.rs | bloc |
version | 0.1.0 |
source | src |
created_at | 2024-08-21 11:00:55.648212 |
updated_at | 2024-08-21 11:00:55.648212 |
description | A state management library |
homepage | |
repository | https://github.com/oxiui/bloc |
max_upload_size | |
id | 1346363 |
size | 14,781 |
Bloc is a library for building scalable and maintainable business logic.
This crate currently only exposes the EnumHandler derive marcro.
// You declare the CounterEvent enum:
use bloc::EnumHandler;
#[derive(EnumHandler)]
pub enum CounterEvent {
Increment,
Decrement,
Reset,
Set(i32),
}
// you can implement the CounterEventHandler trait for your struct:
pub struct Counter;
impl CounterEventHandler for Counter {
fn on_increment(&self) {
println!("Increment");
}
fn on_decrement(&self) {
println!("Decrement");
}
fn on_reset(&self) {
println!("Reset");
}
fn on_set(&self, set: i32) {
println!("Set: {}", set);
}
}
// and the enum_handler macro will generate the following code for you behind the scenes:
pub trait CounterEventHandler {
fn on(&self, e: CounterEvent) -> () {
match (e) {
CounterEvent::Increment => self.on_increment(),
CounterEvent::Decrement => self.on_decrement(),
CounterEvent::Reset => self.on_reset(),
CounterEvent::Set(arg) => self.on_set(arg),
}
}
fn on_increment(&self) -> ();
fn on_decrement(&self) -> ();
fn on_reset(&self) -> ();
fn on_set(&self, set: i32) -> ();
}
Licensed under either of
at your option.