From 688116643d8baec4cc5903fb13cae32711d93a2e Mon Sep 17 00:00:00 2001 From: nanoqsh Date: Wed, 24 Apr 2024 11:44:00 +0500 Subject: [PATCH] Document --- dunge/src/el.rs | 2 +- dunge/src/update.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/dunge/src/el.rs b/dunge/src/el.rs index e50047f..f6d9272 100644 --- a/dunge/src/el.rs +++ b/dunge/src/el.rs @@ -300,7 +300,7 @@ where } } -/// The main event loop control type. +/// The control type of the main event loop. pub struct Control { view: View, resized: Option<(u32, u32)>, diff --git a/dunge/src/update.rs b/dunge/src/update.rs index 7c11d64..7c57a3e 100644 --- a/dunge/src/update.rs +++ b/dunge/src/update.rs @@ -58,6 +58,32 @@ use crate::{ /// dunge::update(upd, draw) /// } /// ``` +/// +/// # Shared state +/// Draw and update stages may share some state. +/// This is not a problem to implement traits manually for some type. +/// However, to be able to use helpers, dunge has the [`update_with_state`] function. +/// ```rust +/// use dunge::{Control, Frame, Update}; +/// +/// struct State { counter: usize } +/// +/// fn make_update() -> impl Update { +/// let draw = |state: &State, frame: Frame| { +/// dbg!(state.counter); +/// }; +/// +/// let upd = |state: &mut State, ctrl: &Control| { +/// state.counter += 1; +/// }; +/// +/// let state = State { counter: 0 }; +/// dunge::update_with_state(state, upd, draw) +/// } +/// ``` +/// +/// Also see the [`update_with_event`] function to set a custom event handler. +/// pub trait Update: Draw { type Flow: Flow; type Event;