pub trait Component {
Show 27 methods
// Required methods
fn component_id(&self) -> ComponentId;
fn state(&self) -> ComponentState;
fn transition_state(&mut self, trigger: ComponentTrigger) -> Result<()>;
fn register(
&mut self,
trader_id: TraderId,
clock: Rc<RefCell<dyn Clock>>,
cache: Rc<RefCell<Cache>>,
) -> Result<()>;
// Provided methods
fn is_ready(&self) -> bool { ... }
fn not_running(&self) -> bool { ... }
fn is_running(&self) -> bool { ... }
fn is_stopped(&self) -> bool { ... }
fn is_degraded(&self) -> bool { ... }
fn is_faulted(&self) -> bool { ... }
fn is_disposed(&self) -> bool { ... }
fn initialize(&mut self) -> Result<()> { ... }
fn start(&mut self) -> Result<()> { ... }
fn stop(&mut self) -> Result<()> { ... }
fn resume(&mut self) -> Result<()> { ... }
fn degrade(&mut self) -> Result<()> { ... }
fn fault(&mut self) -> Result<()> { ... }
fn reset(&mut self) -> Result<()> { ... }
fn dispose(&mut self) -> Result<()> { ... }
fn release_subscriptions(&mut self) { ... }
fn on_start(&mut self) -> Result<()> { ... }
fn on_stop(&mut self) -> Result<()> { ... }
fn on_resume(&mut self) -> Result<()> { ... }
fn on_reset(&mut self) -> Result<()> { ... }
fn on_dispose(&mut self) -> Result<()> { ... }
fn on_degrade(&mut self) -> Result<()> { ... }
fn on_fault(&mut self) -> Result<()> { ... }
}Expand description
Components have state and lifecycle management capabilities.
Required Methods§
Sourcefn component_id(&self) -> ComponentId
fn component_id(&self) -> ComponentId
Returns the unique identifier for this component.
Sourcefn state(&self) -> ComponentState
fn state(&self) -> ComponentState
Returns the current state of the component.
Sourcefn transition_state(&mut self, trigger: ComponentTrigger) -> Result<()>
fn transition_state(&mut self, trigger: ComponentTrigger) -> Result<()>
Transition the component with the state trigger.
§Errors
Returns an error if the trigger is an invalid transition from the current state.
Provided Methods§
Sourcefn not_running(&self) -> bool
fn not_running(&self) -> bool
Returns whether the component is not running.
Sourcefn is_running(&self) -> bool
fn is_running(&self) -> bool
Returns whether the component is running.
Sourcefn is_stopped(&self) -> bool
fn is_stopped(&self) -> bool
Returns whether the component is stopped.
Sourcefn is_degraded(&self) -> bool
fn is_degraded(&self) -> bool
Returns whether the component has been degraded.
Sourcefn is_faulted(&self) -> bool
fn is_faulted(&self) -> bool
Returns whether the component has been faulted.
Sourcefn is_disposed(&self) -> bool
fn is_disposed(&self) -> bool
Returns whether the component has been disposed.
Sourcefn initialize(&mut self) -> Result<()>
fn initialize(&mut self) -> Result<()>
Sourcefn fault(&mut self) -> Result<()>
fn fault(&mut self) -> Result<()>
Faults the component.
§Errors
Returns an error if the component fails to fault.
§Notes
Subscriptions are released whether or not on_fault succeeds, so a faulted component never
keeps message bus handlers installed. Retirement relies on this: it deregisters a Faulted
component without disposing it, which would otherwise leave those handlers behind.
Sourcefn reset(&mut self) -> Result<()>
fn reset(&mut self) -> Result<()>
Resets the component to its initial state.
§Errors
Returns an error if the component fails to reset.
Sourcefn dispose(&mut self) -> Result<()>
fn dispose(&mut self) -> Result<()>
Disposes of the component, releasing any resources.
§Errors
Returns an error if the component fails to dispose.
§Notes
A failing on_dispose releases subscriptions and moves the component to Faulted, then
returns the error. The trader’s registry entries and retained Python wrapper, if any, are
deliberately kept, so the component stays inspectable, while Faulted leaves it retirable.
Subscriptions are released on this path too, because a handler left installed would resolve
a component the trader can now deregister.
on_fault does not run, since invoking a second user hook immediately after on_dispose
failed can fail again.
Sourcefn release_subscriptions(&mut self)
fn release_subscriptions(&mut self)
Releases the message bus registrations this component installed.
Runs on disposal after on_dispose and on faulting after on_fault, so a component the
trader then deregisters leaves behind no handler which would resolve an actor that is no
longer registered. An override must suit both routes rather than assume disposal, and should
be idempotent: a component that faults from inside its own on_dispose releases twice.
Sourcefn on_dispose(&mut self) -> Result<()>
fn on_dispose(&mut self) -> Result<()>
Sourcefn on_degrade(&mut self) -> Result<()>
fn on_degrade(&mut self) -> Result<()>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".