Crates.io | lowbulls |
lib.rs | lowbulls |
version | 0.1.22 |
source | src |
created_at | 2024-05-13 15:14:01.210766 |
updated_at | 2024-05-14 13:11:20.89474 |
description | lowbull is a Rust crate facilitating message handling and event monitoring |
homepage | |
repository | |
max_upload_size | |
id | 1238549 |
size | 27,135 |
'low cost buisness and ui logic seperator'
lowbull
is a Rust crate providing a framework for message handling and event monitoring.
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.
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...
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.
'lowbull' is licensed under the Apache 2.0 license. See LICENSE for details.