feat: add Step/StepMut/StepWith/StepWithMut traits - #108
Conversation
Formalize the pull-based `step` event-loop convention as four traits in a new `step.rs` module, re-exported from the prelude and `future` module. - Step: immutable borrow, for event-listener-only widgets (concurrent racing) - StepMut: exclusive borrow, for widgets that mutate their own fields - StepWith<T>: container racing per-child futures via closure (&self) - StepWithMut<T>: container racing per-child futures via closure (&mut self) All traits use RPITIT (not object-safe) with Output: 'static. This is a non-breaking addition; existing inherent step methods are unaffected. Closes schell-09d
There was a problem hiding this comment.
Pull request overview
Adds a new step module to formalize Mogwai’s pull-based “step” event-loop convention as reusable traits, enabling more generic composition patterns (e.g., containers racing child futures) across the ecosystem.
Changes:
- Introduces
Step,StepMut,StepWith<T>, andStepWithMut<T>traits in a newcrates/mogwai/src/step.rsmodule. - Exposes the new module from
lib.rsand re-exports the traits viaprelude::*and (when enabled)future. - Bumps
mogwaicrate version and updates themogwai-macrosdependency version.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/mogwai/src/step.rs | Adds the four stepping traits and module-level documentation/examples. |
| crates/mogwai/src/lib.rs | Exposes the new step module and re-exports it via the prelude. |
| crates/mogwai/src/future.rs | Re-exports step traits and updates module docs to mention composition with race_all. |
| crates/mogwai/Cargo.toml | Version bump and mogwai-macros dependency version update. |
Suppressed comments (1)
crates/mogwai/src/step.rs:190
- The
step_with_mutcallback type usesdyn Future + '_without tying that lifetime to the&mut Targument. This can prevent returning futures that legitimately borrow from the provided child reference. Use an explicit higher-ranked bound so the returned boxed future is allowed to live for exactly as long as each child borrow.
fn step_with_mut<Ev>(
&mut self,
f: impl FnMut(&mut T) -> Pin<Box<dyn Future<Output = Ev> + '_>>,
) -> impl Future<Output = Self::Output>
where
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- StepWith/StepWithMut: use for<'a> HRTB so returned futures can borrow from the child reference for exactly as long as that borrow lives. - future.rs: clarify race_all requires 'static output (Ev: 'static) even though the future itself may borrow from its child via the HRTB. - Update doc examples to match the new HRTB signatures.
|
Keeping the prelude re-export by design — the |
Formalizes the pull-based
stepevent-loop convention (used across mogwai, iti, mogwai-beads, house-ui, privateer, etc.) as four traits in a newstep.rsmodule.Step:&self— for event-listener-only widgets (enables concurrent racing)StepMut:&mut self— for widgets that mutate their own fieldsStepWith<T>: container racing per-child futures via closure (&self)StepWithMut<T>: container racing per-child futures via closure (&mut self)RPITIT returns (not object-safe),
Output: 'static. Non-breaking — existing inherentstepmethods are unaffected.Closes beads schell-09d.