#message #events #monitoring #logic #framework #low #watch

lowbulls

lowbull is a Rust crate facilitating message handling and event monitoring

10 releases

0.1.22 May 14, 2024
0.1.21 May 14, 2024

#592 in Math

Download history 6/week @ 2024-07-25 1/week @ 2024-08-01 10/week @ 2024-09-19 9/week @ 2024-09-26

204 downloads per month

Apache-2.0

16KB
170 lines

LowBulls

github Latest Version Documentation License

'low cost buisness and ui logic seperator'

lowbull is a Rust crate providing a framework for message handling and event monitoring.

Overview

This crate defines two main modules: core and watch. The core module contains foundational traits and types for message handling, while the watch module provides utilities for monitoring events.

Usage

To use lowbull, add it as a dependency in your Cargo.toml:

[dependencies]
lowbull = "0.1.11"

Then, you can use the crate in your Rust code by importing the necessary modules:

use lowbull::core::LowBullMaster;
use lowbull::watch::LowBullWatcher;
use anyhow::Result;

// Your code here...

Examples

Here's a simple example demonstrating the usage of lowbull:

use lowbull::core::LowBullMaster;
use lowbull::watch::LowBullWatcher;
use lowbull::anyhow::Result;

// Define message types
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
enum Message {
    StartRender,
    StopRender,
}

// Define response types
#[derive(Debug, Hash, PartialEq, Eq)]
enum Response {
    None,
}

#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
enum ResourceKey {
    GetTest,
    GetRender,
}
    
#[derive(Debug, Hash, PartialEq, Eq)]
enum Resource {
    Render(bool),
    Test(bool),
}

// Implement a message handler
struct Master {
    render: bool,
    #[cfg(debug_assertions)]
    handle_watcher: watch::LowBullWatcher<HandleKey>,
    #[cfg(debug_assertions)]
    resource_watcher: RefCell<watch::LowBullWatcher<ResourceKey>>,
}

impl LowBullMaster<HandleKey, Response, ResourceKey, Resource> for Master {
    fn handle(&mut self, key: HandleKey) -> Result<Response> {
        if cfg!(debug_assertions) {
            self.handle_watcher.watch(key);
        }

        match key {
            HandleKey::StartRender => {
                self.render = true;
                Ok(Response::None)
            }
            HandleKey::StopRender => {
                self.render = false;
                Ok(Response::None)
            }
            HandleKey::Empty => Ok(Response::None),
        }
    }

    fn get_resource(&self, key: ResourceKey) -> Result<Resource> {
        if cfg!(debug_assertions) {
            self.resource_watcher.borrow_mut().watch(key);
        }

        match key {
            ResourceKey::GetTest => Ok(Resource::Test(true)),
            ResourceKey::GetRender => Ok(Resource::Render(self.render)),
        }
    }
}

// Your code here...

For more examples and detailed usage, please refer to the documentation.

License

'lowbull' is licensed under the Apache 2.0 license. See LICENSE for details.

Dependencies

~135KB