diff --git a/Cargo.lock b/Cargo.lock index defd5bc..686fdb7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1162,7 +1162,7 @@ dependencies = [ [[package]] name = "teatui" -version = "0.2.1" +version = "0.3.0" dependencies = [ "crossterm", "ratatui", diff --git a/examples/counter/src/main.rs b/examples/counter/src/main.rs index 9b67d06..aa20004 100644 --- a/examples/counter/src/main.rs +++ b/examples/counter/src/main.rs @@ -101,14 +101,14 @@ pub fn update(model: Model, msg: Message) -> Update { } } -pub fn run_effects(_model: &Model, _effect: Effect) -> Option { +pub fn run_effects(_model: Model, _effect: Effect) -> Option { None } /// Elm-like View function. /// /// Given the current state (read-only), return a drawable widget. -pub fn view(model: &Model) -> Paragraph<'static> { +pub fn view(model: Model) -> Paragraph<'static> { let counter = model.counter; let title = Line::from("Ratatui Actor-based Counter") diff --git a/teatui/Cargo.toml b/teatui/Cargo.toml index d9192a5..163ddb7 100644 --- a/teatui/Cargo.toml +++ b/teatui/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "teatui" -version = "0.3.0" +version = "0.4.0" description = "An elm-like abstraction over Ratatui" license.workspace = true authors.workspace = true diff --git a/teatui/src/effects.rs b/teatui/src/effects.rs index 3edabf0..9162fea 100644 --- a/teatui/src/effects.rs +++ b/teatui/src/effects.rs @@ -18,14 +18,14 @@ pub(crate) fn run( ) -> Result<(), EffectsError> where Msg: Send + Sync + 'static, - F: Fn(&M, Eff) -> Option, + F: Fn(M, Eff) -> Option, { loop { let Ok((model, effect)) = rx.recv() else { return Ok(()); }; - if let Some(msg) = effects_fn(&model, effect) { + if let Some(msg) = effects_fn(model, effect) { tx.send(msg)?; } } @@ -42,7 +42,7 @@ where Msg: Send + Sync + 'static, Eff: Send + Sync + 'static, Fut: Future> + Send, - F: Fn(&M, Eff) -> Fut + Send + Sync + 'static, + F: Fn(M, Eff) -> Fut + Send + Sync + 'static, { let rt = tokio::runtime::Builder::new_current_thread() .enable_all() @@ -56,7 +56,7 @@ where }; // We spawn the effect in the tokio reactor so they can run concurrently - let fut = effects_fn(&model, effect); + let fut = effects_fn(model, effect); if let Some(msg) = fut.await { let _ = tx.send(msg); diff --git a/teatui/src/lib.rs b/teatui/src/lib.rs index 362489f..7e2da7b 100644 --- a/teatui/src/lib.rs +++ b/teatui/src/lib.rs @@ -87,8 +87,8 @@ where W: Widget, IF: Fn() -> (M, Option) + Send + Sync + 'static, UF: Fn(M, Msg) -> Update + Send + Sync + 'static, - VF: Fn(&M) -> W + Send + Sync + 'static, - EF: Fn(&M, Eff) -> Option + Send + Sync + 'static, + VF: Fn(M) -> W + Send + Sync + 'static, + EF: Fn(M, Eff) -> Option + Send + Sync + 'static, { run_program(init_fn, update_fn, view_fn, move |effects_rx, update_tx| { effects::run(effects_fn, effects_rx, update_tx) @@ -110,8 +110,8 @@ where W: Widget, IF: Fn() -> (M, Option) + Send + Sync + 'static, UF: Fn(M, Msg) -> Update + Send + Sync + 'static, - VF: Fn(&M) -> W + Send + Sync + 'static, - EF: Fn(&M, Eff) -> Fut + Send + Sync + 'static, + VF: Fn(M) -> W + Send + Sync + 'static, + EF: Fn(M, Eff) -> Fut + Send + Sync + 'static, Fut: std::future::Future> + Send, { run_program(init_fn, update_fn, view_fn, move |effects_rx, update_tx| { @@ -133,7 +133,7 @@ where W: Widget, IF: Fn() -> (M, Option) + Send + Sync + 'static, UF: Fn(M, Msg) -> Update + Send + Sync + 'static, - VF: Fn(&M) -> W + Send + Sync + 'static, + VF: Fn(M) -> W + Send + Sync + 'static, SF: FnOnce( std::sync::mpsc::Receiver<(M, Eff)>, std::sync::mpsc::Sender, diff --git a/teatui/src/view.rs b/teatui/src/view.rs index a44bd64..9500315 100644 --- a/teatui/src/view.rs +++ b/teatui/src/view.rs @@ -17,10 +17,10 @@ pub(crate) fn run( ) -> Result<(), ViewError> where W: Widget, - F: Fn(&M) -> W, + F: Fn(M) -> W, { loop { - let widget = view_fn(&model); + let widget = view_fn(model); terminal.draw(|frame| frame.render_widget(widget, frame.area()))?;