bloc

Crates.iobloc
lib.rsbloc
version0.1.0
sourcesrc
created_at2024-08-21 11:00:55.648212
updated_at2024-08-21 11:00:55.648212
descriptionA state management library
homepage
repositoryhttps://github.com/oxiui/bloc
max_upload_size
id1346363
size14,781
Andreas Gorges (agorges)

documentation

README

Bloc (Business Logic Component)

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

License

Licensed under either of

at your option.

Commit count: 0

cargo fmt