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>
impl<S, L, A> CuAppLifecycle<S, L, A, Initialized>
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>
impl<S, L, A, State> CuAppLifecycle<S, L, A, State>
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>
impl<S, L, A> CuAppLifecycle<S, L, A, Running>
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>
impl<S, L, A, State> CuAppLifecycle<S, L, A, State>
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>
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>
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§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 T
impl<T> GetTypeRegistration 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