Crates.io | rearch-effects |
lib.rs | rearch-effects |
version | 0.6.0 |
source | src |
created_at | 2023-12-26 08:07:49.752654 |
updated_at | 2024-08-07 17:22:55.246814 |
description | Re-imagined approach to application design and architecture |
homepage | https://rearch.gsconrad.com |
repository | https://github.com/GregoryConrad/rearch-rs |
max_upload_size | |
id | 1080714 |
size | 52,344 |
ReArch = re-imagined approach to application design and architecture
We must state definitions and provide for priorities and descriptions of data. We must state relationships, not procedures.
-- Grace Murray Hopper, Management and the Computer of the Future (1962)
Specifically, ReArch is a novel solution to:
And with those, come:
Reactivity through declarative code
Loose coupling and high testability
App-level composability via a functional approach to dependency inversion
Define your "capsules" (en-capsulated pieces of state) at the top level:
// Capsules are simply functions that consume a CapsuleHandle.
// The CapsuleHandle lets you get the state of other capsules,
// in addition to using a large variety of side effects.
// This capsule provides the count and a way to increment that count.
fn count_manager(CapsuleHandle { register, .. }: CapsuleHandle) -> (u8, impl CData + Fn()) {
let (count, set_count) = register(effects::state::<Cloned<_>>(0));
let increment_count = move || set_count(count + 1);
(count, increment_count)
}
// This capsule provides the count, plus one.
fn count_plus_one_capsule(CapsuleHandle { mut get, .. }: CapsuleHandle) -> u8 {
let (count, _increment_count) = get(count_manager);
count + 1
}
let container = Container::new();
let ((count, increment_count), count_plus_one) =
container.read((count_manager, count_plus_one_capsule));
assert_eq!(count, 0);
assert_eq!(count_plus_one, 1);
increment_count();
let ((count, _), count_plus_one) =
container.read((count_manager, count_plus_one_capsule));
assert_eq!(count, 1);
assert_eq!(count_plus_one, 2);
Simply run:
cargo add rearch rearch-effects
Then, create one container for your application:
use rearch::*;
use rearch_effects as effects;
fn main() {
let container = Container::new();
// Use the container.
}
And take a look at the examples to get an idea on how to make some of your own capsules!
Also, there is some WIP documentation that will help you learn the core concepts behind ReArch!
The MSRV of rearch
is currently 1.75.0 and may change in any new ReArch version/release.
The MSRV of other crates in this repo will be the latest stable release for the foreseeable future.
It is also worth mentioning that the example shown in "In a Nutshell" above requires nightly
for unboxed_closures
and fn_traits
, which is feature-gated under the experimental-api
feature.
Once unboxed_closures
and fn_traits
stabilize,
this nightly syntax will be the preferred syntax,
and this will no longer be feature-gated.
(Without nightly, you must instead call the slightly more verbose
get.as_ref(some_capsule).clone()
and register.register(effect())
.)
As much as I have done with ReArch, it always seems like there is more to do. One person can only do so much!
If you would like to contribute, here are some areas where I would really appreciate help!
You can become a sponsor of my work here!