oxide_mvu/
lib.rs

1#![cfg_attr(feature = "no_std", no_std)]
2
3//! A lightweight Model-View-Update (MVU) runtime for Rust with `no_std` support.
4//!
5//! Implements the MVU pattern for building predictable, testable applications with
6//! unidirectional data flow and controlled side effects.
7//!
8//! ## Example
9//!
10//! ```rust
11//! use oxide_mvu::{Emitter, Effect, MvuLogic, MvuRuntime, Renderer};
12//!
13//! #[derive(Clone)]
14//! enum Event { AccumulateClicked }
15//!
16//! #[derive(Clone)]
17//! struct Model { count: i32 }
18//!
19//! struct Props { count: i32, on_accumulate_click: Box<dyn Fn()> }
20//!
21//! struct MyLogic;
22//!
23//! impl MvuLogic<Event, Model, Props> for MyLogic {
24//!     fn init(&self, model: Model) -> (Model, Effect<Event>) {
25//!         (model, Effect::none())
26//!     }
27//!
28//!     fn update(&self, event: Event, model: &Model) -> (Model, Effect<Event>) {
29//!         match event {
30//!             Event::AccumulateClicked => {
31//!                 let new_model = Model {
32//!                     count: model.count + 1,
33//!                     ..model.clone()
34//!                 };
35//!                 (new_model, Effect::none())
36//!             }
37//!         }
38//!     }
39//!
40//!     fn view(&self, model: &Model, emitter: &Emitter<Event>) -> Props {
41//!         let emitter = emitter.clone();
42//!         Props {
43//!             count: model.count,
44//!             on_accumulate_click: Box::new(move || emitter.emit(Event::AccumulateClicked))
45//!         }
46//!     }
47//! }
48//!
49//! struct MyRenderer;
50//! impl Renderer<Props> for MyRenderer {
51//!     fn render(&mut self, _props: Props) {}
52//! }
53//!
54//! let runtime = MvuRuntime::new(
55//!     Model { count: 0 },
56//!     Box::new(MyLogic),
57//!     Box::new(MyRenderer)
58//! );
59//! runtime.run();
60//! ```
61
62#[cfg(feature = "no_std")]
63extern crate alloc;
64
65// Module declarations
66mod effect;
67mod emitter;
68mod logic;
69mod renderer;
70mod runtime;
71
72// Public re-exports
73pub use effect::Effect;
74pub use emitter::Emitter;
75pub use logic::MvuLogic;
76pub use renderer::Renderer;
77pub use runtime::MvuRuntime;
78
79// Test utilities (only available with 'testing' feature or during tests)
80#[cfg(any(test, feature = "testing"))]
81pub use renderer::TestRenderer;
82#[cfg(any(test, feature = "testing"))]
83pub use runtime::{TestMvuDriver, TestMvuRuntime};