Skip to content

Commit

Permalink
Make Signal::should_stop public
Browse files Browse the repository at this point in the history
And use it in the TryFrom<Signal> impl for Terminate, which uses the
same logic.
  • Loading branch information
Thomasdezeeuw committed Nov 24, 2023
1 parent 2d248eb commit 62d6491
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions rt/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl Signal {
}

/// Whether or not the `Signal` is considered a "stopping" signal.
pub(crate) const fn should_stop(self) -> bool {
pub const fn should_stop(self) -> bool {
matches!(self, Signal::Interrupt | Signal::Terminate | Signal::Quit)
}

Expand Down Expand Up @@ -401,12 +401,14 @@ impl fmt::Display for Signal {
impl TryFrom<Signal> for Terminate {
type Error = ();

/// Converts [`Signal::Interrupt`], [`Signal::Terminate`] and
/// [`Signal::Quit`], fails for all other signals (by returning `Err(())`).
/// Converts the `signal` into a `Terminate` message if
/// [`signal.should_stop`] returns true, fails for all other signals (by
/// returning `Err(())`).
fn try_from(signal: Signal) -> Result<Self, Self::Error> {
match signal {
Signal::Interrupt | Signal::Terminate | Signal::Quit => Ok(Terminate),
_ => Err(()),
if signal.should_stop() {
Ok(Terminate)
} else {
Err(())
}
}
}

0 comments on commit 62d6491

Please sign in to comment.