pub struct CuAppLifecycle<S, L, A, State = Initialized> { /* private fields */ }Expand description
Compile-time enforced lifecycle for a CuApplication.
Wrapping an application moves lifecycle mistakes (double start, iterating
before start, mixing start_all_tasks with run…) from runtime surprises
to compile errors: each state is a distinct type exposing only the
transitions that are legal from it.
start
Initialized ------------------> Running <---+
| | | | run_one_iteration
| run_until_shutdown | +------+
| | stop
+--------> Stopped <---------+
| ^
| | stop (cleanup)
(restart) | Faulted <--- any failed transition
+---> start / run_until_shutdown againTransitions consume the wrapper and return it typed with the new state, so
a stale pre-transition handle cannot be reused. When a transition fails,
the application is handed back inside LifecycleError, typed Faulted,
so cleanup is still possible and nothing is lost.
This is the default construction path: the generated application builder
hands one out from build_app(). The raw CuApplication methods remain
available (deprecated on the generated application) for framework-level
harnesses such as replay engines; into_inner
drops back to that level when needed.
The application is boxed internally: generated applications embed their copperlist pools and can be megabytes, so the consuming transitions move a pointer instead of the application itself (which in debug builds would blow through a test thread’s stack).
Implementations§
Source§impl<S, L, A, State> CuAppLifecycle<S, L, A, State>
impl<S, L, A, State> CuAppLifecycle<S, L, A, State>
Sourcepub fn into_inner(self) -> A
pub fn into_inner(self) -> A
Consumes the wrapper and returns the application, dropping the compile-time lifecycle tracking.
Source§impl<S, L, A> CuAppLifecycle<S, L, A, Initialized>where
S: SectionStorage,
L: UnifiedLogWrite<S> + 'static,
A: CuApplication<S, L>,
impl<S, L, A> CuAppLifecycle<S, L, A, Initialized>where
S: SectionStorage,
L: UnifiedLogWrite<S> + 'static,
A: CuApplication<S, L>,
Sourcepub fn inner_mut(&mut self) -> &mut A
pub fn inner_mut(&mut self) -> &mut A
Mutable access to the wrapped application, only before it is started.
This exists for pre-start configuration (attaching monitors,
inspecting the runtime…). Once started, only the read-only
inner view remains available so the
lifecycle transitions cannot be bypassed mid-flight.
Source§impl<S, L, A, State> CuAppLifecycle<S, L, A, State>where
S: SectionStorage,
L: UnifiedLogWrite<S> + 'static,
A: CuApplication<S, L>,
State: Startable,
impl<S, L, A, State> CuAppLifecycle<S, L, A, State>where
S: SectionStorage,
L: UnifiedLogWrite<S> + 'static,
A: CuApplication<S, L>,
State: Startable,
Sourcepub fn start(self) -> TransitionResult<S, L, A, Running>
pub fn start(self) -> TransitionResult<S, L, A, Running>
Starts all tasks, transitioning to Running.
On failure the application may be partially started; it is returned
typed Faulted inside the error so it can be cleaned up.
Sourcepub fn run_until_shutdown(self) -> TransitionResult<S, L, A, Stopped>
pub fn run_until_shutdown(self) -> TransitionResult<S, L, A, Stopped>
Runs the full lifecycle (start, iterate until shutdown, stop),
transitioning to Stopped on success.
Source§impl<S, L, A> CuAppLifecycle<S, L, A, Running>where
S: SectionStorage,
L: UnifiedLogWrite<S> + 'static,
A: CuApplication<S, L>,
impl<S, L, A> CuAppLifecycle<S, L, A, Running>where
S: SectionStorage,
L: UnifiedLogWrite<S> + 'static,
A: CuApplication<S, L>,
Sourcepub fn run_one_iteration(&mut self) -> CuResult<()>
pub fn run_one_iteration(&mut self) -> CuResult<()>
Executes one iteration of the runtime. An iteration error does not change the lifecycle state: the caller decides whether to keep iterating or stop.
Source§impl<S, L, A, State> CuAppLifecycle<S, L, A, State>where
S: SectionStorage,
L: UnifiedLogWrite<S> + 'static,
A: CuApplication<S, L>,
State: Stoppable,
impl<S, L, A, State> CuAppLifecycle<S, L, A, State>where
S: SectionStorage,
L: UnifiedLogWrite<S> + 'static,
A: CuApplication<S, L>,
State: Stoppable,
Sourcepub fn stop(self) -> TransitionResult<S, L, A, Stopped>
pub fn stop(self) -> TransitionResult<S, L, A, Stopped>
Stops all tasks, transitioning to Stopped. From Faulted this is a
best-effort cleanup. On failure the application is handed back typed
Faulted again.
Trait Implementations§
Source§impl<S, L, A> CuApplication<S, L> for CuAppLifecycle<S, L, A, Initialized>where
S: SectionStorage,
L: UnifiedLogWrite<S> + 'static,
A: CuApplication<S, L>,
Legacy escape hatch: the raw (deprecated) lifecycle API remains callable
on what build() returns, so pre-typestate code compiles unchanged and
only picks up deprecation warnings. Raw calls do not advance the
typestate; mixing them with typed transitions is outside the typestate
guarantees.
impl<S, L, A> CuApplication<S, L> for CuAppLifecycle<S, L, A, Initialized>where
S: SectionStorage,
L: UnifiedLogWrite<S> + 'static,
A: CuApplication<S, L>,
Legacy escape hatch: the raw (deprecated) lifecycle API remains callable
on what build() returns, so pre-typestate code compiles unchanged and
only picks up deprecation warnings. Raw calls do not advance the
typestate; mixing them with typed transitions is outside the typestate
guarantees.
Source§fn get_original_config() -> String
fn get_original_config() -> String
Source§fn start_all_tasks(&mut self) -> CuResult<()>
fn start_all_tasks(&mut self) -> CuResult<()>
use the typed transition start() on the handle returned by build()
Source§fn run_one_iteration(&mut self) -> CuResult<()>
fn run_one_iteration(&mut self) -> CuResult<()>
use run_one_iteration() on the Running handle from build()?.start()?
Source§fn run(&mut self) -> CuResult<()>
fn run(&mut self) -> CuResult<()>
use the typed transition run_until_shutdown() on the handle returned by build()
Source§fn stop_all_tasks(&mut self) -> CuResult<()>
fn stop_all_tasks(&mut self) -> CuResult<()>
use the typed transition stop() on the Running handle
Source§fn restore_keyframe(&mut self, freezer: &KeyFrame) -> CuResult<()>
fn restore_keyframe(&mut self, freezer: &KeyFrame) -> CuResult<()>
Source§impl<S, L, A, State> Debug for CuAppLifecycle<S, L, A, State>
impl<S, L, A, State> Debug for CuAppLifecycle<S, L, A, State>
Source§impl<S, L, A, State> Deref for CuAppLifecycle<S, L, A, State>
Read access to the wrapped application in every lifecycle state, so
conveniences like app.clock() keep working without ceremony.
impl<S, L, A, State> Deref for CuAppLifecycle<S, L, A, State>
Read access to the wrapped application in every lifecycle state, so
conveniences like app.clock() keep working without ceremony.
Source§impl<S, L, A> DerefMut for CuAppLifecycle<S, L, A, Initialized>
Mutable access only before the application is started: after a typed
start, raw mutable access could bypass the lifecycle guarantees.
impl<S, L, A> DerefMut for CuAppLifecycle<S, L, A, Initialized>
Mutable access only before the application is started: after a typed start, raw mutable access could bypass the lifecycle guarantees.
Auto Trait Implementations§
impl<S, L, A, State> Freeze for CuAppLifecycle<S, L, A, State>
impl<S, L, A, State> RefUnwindSafe for CuAppLifecycle<S, L, A, State>
impl<S, L, A, State> Send for CuAppLifecycle<S, L, A, State>
impl<S, L, A, State> Sync for CuAppLifecycle<S, L, A, State>
impl<S, L, A, State> Unpin for CuAppLifecycle<S, L, A, State>
impl<S, L, A, State> UnsafeUnpin for CuAppLifecycle<S, L, A, State>
impl<S, L, A, State> UnwindSafe for CuAppLifecycle<S, L, A, State>
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
impl<T> CuStdApplication for Twhere
T: CuApplication<MmapSectionStorage, MmapUnifiedLoggerWrite>,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more