Skip to main content

ApplicationRunner

Struct ApplicationRunner 

Source
pub struct ApplicationRunner;
Expand description

TUI application runner

Encapsulates the lifecycle of running a TUI application: creating the event channel, constructing the Context, building a Projection inside a Tokio runtime, registering signal handlers, and calling the application function. Unlike CommandRunner, there is no presenter — the application owns its own render loop and queries the projection for accumulated state.

§Examples

// This is what main!() expands to for applications:
ResolvedLeaf::Application { matches, exec } => {
    clawless::tui::runner::ApplicationRunner::run(matches, exec)
}

Implementations§

Source§

impl ApplicationRunner

Source

pub fn run<E, F>(matches: ArgMatches, exec: E) -> Result<(), Box<dyn Error>>
where E: FnOnce(ArgMatches, Context, Projection) -> F, F: Future<Output = Result<()>> + Send + 'static,

Runs a TUI application to completion

Sets up the application lifecycle:

  1. Creates a Cancellation token for cooperative shutdown
  2. Creates an event channel and builds the Context
  3. Creates a Tokio runtime
  4. Inside the runtime, creates a Projection (which spawns a background drain task)
  5. Spawns the signal handler and calls the application function

The Projection must be created inside the Tokio runtime because its constructor calls tokio::spawn to start the background event drain.

§Arguments
  • matches — The parsed ArgMatches for this application leaf, as resolved by the subcommand tree walk.
  • exec — Executes the application with the given matches, context, and projection. The #[application] macro generates a function for this, and any other callable works. A caller that builds its command tree at run time passes a closure that owns the application it resolved.
§Errors

Returns an error if context construction fails (e.g., the current working directory cannot be determined), if the Tokio runtime cannot be created, or if the application itself fails.

Trait Implementations§

Source§

impl Debug for ApplicationRunner

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.