pub struct ModuleInstance<S: State> { /* private fields */ }Expand description
A running module instance with live state.
Created from a ModuleDefinition when the module is mounted.
Wraps a hypen_engine::Engine and manages state synchronization.
Implementations§
Source§impl<S: State> ModuleInstance<S>
impl<S: State> ModuleInstance<S>
Sourcepub fn new(
definition: Arc<ModuleDefinition<S>>,
global_context: Option<Arc<GlobalContext>>,
) -> Result<Self>
pub fn new( definition: Arc<ModuleDefinition<S>>, global_context: Option<Arc<GlobalContext>>, ) -> Result<Self>
Create a new module instance from a definition.
Sourcepub fn new_with_components(
definition: Arc<ModuleDefinition<S>>,
global_context: Option<Arc<GlobalContext>>,
components: &ComponentRegistry,
) -> Result<Self>
pub fn new_with_components( definition: Arc<ModuleDefinition<S>>, global_context: Option<Arc<GlobalContext>>, components: &ComponentRegistry, ) -> Result<Self>
Create a new module instance with a component registry for resolving child components in the UI template.
This enables DSL like Column { Feed {} } where Feed is registered
in the ComponentRegistry. Without a registry, the engine cannot resolve
custom component references in the template.
§Example
let mut registry = ComponentRegistry::new();
registry.register("Card", r#"Column { Text("Card") }"#, None);
let instance = ModuleInstance::new_with_components(
Arc::new(def),
Some(ctx),
®istry,
).unwrap();Sourcepub fn mount(&self)
pub fn mount(&self)
Mount the module: fire the initial render, then run on_created
(sync only).
The initial render is deferred from construction to mount() so
callers can wire on_patches(cb) in between and capture the
initial Create batch. Subsequent mount() calls are no-ops; the
pending IR slot is consumed on the first call.
Async-only lifecycle handlers are silently skipped here — call
mount_async to invoke them.
Sourcepub fn activate(&self)
pub fn activate(&self)
Fire on_activated (sync only). Called by [ManagedRouter] every
time the module gains the active route slot — including persist
cache restores. Independent of mount; does not
flip mounted.
Sourcepub fn deactivate(&self)
pub fn deactivate(&self)
Fire on_deactivated (sync only). Paired with
activate; fires before on_destroyed or
before the persist-cache write.
Sourcepub fn unmount(&self)
pub fn unmount(&self)
Unmount the module (triggers on_destroyed if it was registered as sync).
Async-only lifecycle handlers are silently skipped here — call
unmount_async to invoke them.
Sourcepub fn dispatch_action(
&self,
name: impl Into<String>,
payload: Option<Value>,
) -> Result<()>
pub fn dispatch_action( &self, name: impl Into<String>, payload: Option<Value>, ) -> Result<()>
Dispatch an action by name with an optional payload.
Only sync handlers run here. Actions registered as async-only return
ActionNotFound — call dispatch_action_async
for async handlers.
The dispatch routes through engine.dispatch_action(...), which fires
the per-action closure registered in register_action_handlers_with_engine
during construction. That closure runs the typed handler against the
per-instance state. After dispatch returns, this method diffs the
state against its pre-handler snapshot and pushes any changed paths
to the engine via engine.update_state(None, patch).
Sourcepub fn get_state_json(&self) -> Result<Value>
pub fn get_state_json(&self) -> Result<Value>
Get the current state as JSON.
Sourcepub fn on_patches<F>(&self, callback: F)
pub fn on_patches<F>(&self, callback: F)
Set the render callback for receiving patches.
Sourcepub fn is_mounted(&self) -> bool
pub fn is_mounted(&self) -> bool
Check if the module is currently mounted.
Trait Implementations§
Source§impl<S: State> ManagedModule for ModuleInstance<S>
impl<S: State> ManagedModule for ModuleInstance<S>
fn name(&self) -> &str
fn mount(&self)
fn activate(&self)
fn deactivate(&self)
fn destroy(&self)
Source§fn is_persistent(&self) -> bool
fn is_persistent(&self) -> bool
false — match the TS / Swift contract where
persistence is opt-in via .persist().Auto Trait Implementations§
impl<S> !Freeze for ModuleInstance<S>
impl<S> !RefUnwindSafe for ModuleInstance<S>
impl<S> !UnwindSafe for ModuleInstance<S>
impl<S> Send for ModuleInstance<S>
impl<S> Sync for ModuleInstance<S>
impl<S> Unpin for ModuleInstance<S>
impl<S> UnsafeUnpin for ModuleInstance<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Erasable for T
impl<T> Erasable for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);