Skip to main content

Termination

Enum Termination 

Source
#[non_exhaustive]
pub enum Termination { Terminate, Hangup, }
Expand description

Why the system, rather than the user, is ending the application.

On Unix the terminal Runtime catches SIGTERM, SIGINT and SIGHUP for as long as it runs, and a Harness simulates them with Harness::terminate. The application hears the cause through App::terminating, which is how it tells “the system is ending us” from “the user asked to quit” (App::before_quit).

Whatever the application answers, the run ends in bounded time:

  • Answering None quits at once.
  • A message keeps the application running while it finishes, e.g. saves and returns Command::quit. After Termination::grace the runtime quits without it.
  • A second SIGTERM or SIGINT ends the run at once. When the application does not return to the loop within a second after that, or after its grace, the runtime restores the terminal itself and the process ends by the signal, as it would have without the framework.

Every quit restores the terminal (raw mode off, the normal screen, the cursor) as long as the terminal still exists; after a hangup nothing is written to it.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Terminate

SIGTERM, or SIGINT from kill -INT: another program or the system (a service manager, a shutdown, kill) asks the application to end. The terminal is still there, so the application may save and quit, and it may even ask the user something, within the grace. By default the application answers as for a quit the user asked for, with App::before_quit.

Inside the application ctrl c is a key, not this signal: raw mode turns the terminal’s interrupt key off.

§

Hangup

SIGHUP: the terminal went away, because the SSH connection dropped, the terminal window or the tmux pane closed. Nobody can answer a question any more and nothing is drawn after it, so the application gets one chance to save, without a dialog. By default it quits at once.

A hangup that repeats (the shell forwards its own and the system sends another when the shell ends) changes nothing. A SIGHUP sent by hand while the terminal is still there is heard the same way, and the terminal is restored on the way out.

Implementations§

Source§

impl Termination

Source

pub const fn grace(self) -> Duration

How long the application has, after this cause, to quit on its own before the runtime quits without it: five seconds after Termination::Terminate, three after Termination::Hangup. A hangup during a pending terminate shortens what is left to the hangup’s grace.

use std::time::Duration;
use qframe::runtime::Termination;

assert_eq!(Termination::Terminate.grace(), Duration::from_secs(5));
assert_eq!(Termination::Hangup.grace(), Duration::from_secs(3));

Trait Implementations§

Source§

impl Clone for Termination

Source§

fn clone(&self) -> Termination

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Termination

Source§

impl Debug for Termination

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Termination

Source§

impl Hash for Termination

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Termination

Source§

fn eq(&self, other: &Termination) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Termination

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, !>

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.