lowbulls

Crates.iolowbulls
lib.rslowbulls
version0.1.22
sourcesrc
created_at2024-05-13 15:14:01.210766
updated_at2024-05-14 13:11:20.89474
descriptionlowbull is a Rust crate facilitating message handling and event monitoring
homepage
repository
max_upload_size
id1238549
size27,135
Elias Gottsbacher (GodGotzi)

documentation

README

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.

Commit count: 0

cargo fmt