Skip to content

feat: add Step/StepMut/StepWith/StepWithMut traits - #108

Merged
schell merged 3 commits into
mainfrom
feat/step-traits
Aug 8, 2026
Merged

schell merged 3 commits into
mainfrom
feat/step-traits

Conversation

@schell

@schell schell commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Formalizes the pull-based step event-loop convention (used across mogwai, iti, mogwai-beads, house-ui, privateer, etc.) as four traits in a new step.rs module.

  • Step: &self — for event-listener-only widgets (enables concurrent racing)
  • StepMut: &mut self — 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)

RPITIT returns (not object-safe), Output: 'static. Non-breaking — existing inherent step methods are unaffected.

Closes beads schell-09d.

schell added 2 commits July 15, 2026 11:32
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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>, and StepWithMut<T> traits in a new crates/mogwai/src/step.rs module.
  • Exposes the new module from lib.rs and re-exports the traits via prelude::* and (when enabled) future.
  • Bumps mogwai crate version and updates the mogwai-macros dependency 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_mut callback type uses dyn Future + '_ without tying that lifetime to the &mut T argument. 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.

Comment thread crates/mogwai/src/lib.rs
Comment thread crates/mogwai/src/future.rs Outdated
Comment thread crates/mogwai/src/step.rs
- 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.
@schell

schell commented Aug 8, 2026

Copy link
Copy Markdown
Owner Author

Keeping the prelude re-export by design — the step convention is intended to be the idiomatic way all mogwai widgets advance, so the traits belong in the prelude alongside view::* and proxy::*. The name-conflict risk is accepted: Step/StepMut/StepWith/StepWithMut are novel names unlikely to collide with user types, and any downstream that has its own Step trait can disambiguate with explicit imports.

@schell
schell merged commit d693195 into main Aug 8, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants