Skip to main content

CuAppLifecycle

Struct CuAppLifecycle 

Source
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 again

Transitions 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>

Source

pub fn inner(&self) -> &A

Read-only access to the wrapped application.

Source

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>,

Source

pub fn new(app: A) -> Self

Wraps a freshly built application in the Initialized state.

Source

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,

Source

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.

Source

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>,

Source

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,

Source

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.

Source§

fn get_original_config() -> String

Returns the original configuration as a string, typically loaded from a RON file. This configuration represents the default settings for the application before any overrides.
Source§

fn start_all_tasks(&mut self) -> CuResult<()>

👎Deprecated since 1.2.0:

use the typed transition start() on the handle returned by build()

Starts all tasks managed by the application/runtime. Read more
Source§

fn run_one_iteration(&mut self) -> CuResult<()>

👎Deprecated since 1.2.0:

use run_one_iteration() on the Running handle from build()?.start()?

Executes a single iteration of copper-generated runtime (generating and logging one copperlist) Read more
Source§

fn run(&mut self) -> CuResult<()>

👎Deprecated since 1.2.0:

use the typed transition run_until_shutdown() on the handle returned by build()

Runs indefinitely looping over run_one_iteration Read more
Source§

fn stop_all_tasks(&mut self) -> CuResult<()>

👎Deprecated since 1.2.0:

use the typed transition stop() on the Running handle

Stops all tasks managed by the application/runtime. Read more
Source§

fn restore_keyframe(&mut self, freezer: &KeyFrame) -> CuResult<()>

Restore all tasks from the given frozen state
Source§

impl<S, L, A, State> Debug for CuAppLifecycle<S, L, A, State>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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.

Source§

type Target = A

The resulting type after dereferencing.
Source§

fn deref(&self) -> &A

Dereferences the value.
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.

Source§

fn deref_mut(&mut self) -> &mut A

Mutably dereferences the value.

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>
where A: Send, S: Send, L: Send, State: Send,

§

impl<S, L, A, State> Sync for CuAppLifecycle<S, L, A, State>
where A: Sync, S: Sync, L: Sync, State: Sync,

§

impl<S, L, A, State> Unpin for CuAppLifecycle<S, L, A, State>
where S: Unpin, L: Unpin, State: Unpin,

§

impl<S, L, A, State> UnsafeUnpin for CuAppLifecycle<S, L, A, State>

§

impl<S, L, A, State> UnwindSafe for CuAppLifecycle<S, L, A, State>
where A: UnwindSafe, S: UnwindSafe, L: UnwindSafe, State: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CuStdApplication for T
where T: CuApplication<MmapSectionStorage, MmapUnifiedLoggerWrite>,

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<A> Is for A
where A: Any,

§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> PayloadDefaultHandlePolicyApply for T
where T: ?Sized,

Source§

impl<T> PayloadDefaultLoggingPolicy for T
where T: ?Sized,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.