Skip to content

Commit

Permalink
signal: make SignalKind methods const (#4956)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdeafbeef authored Aug 29, 2022
1 parent 505cc09 commit ba93b28
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions tokio/src/signal/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl SignalKind {
// unlikely to change to other types, but technically libc can change this
// in the future minor version.
// See https://github.com/tokio-rs/tokio/issues/3767 for more.
pub fn from_raw(signum: std::os::raw::c_int) -> Self {
pub const fn from_raw(signum: std::os::raw::c_int) -> Self {
Self(signum as libc::c_int)
}

Expand All @@ -95,31 +95,31 @@ impl SignalKind {
/// let kind = SignalKind::interrupt();
/// assert_eq!(kind.as_raw_value(), libc::SIGINT);
/// ```
pub fn as_raw_value(&self) -> std::os::raw::c_int {
pub const fn as_raw_value(&self) -> std::os::raw::c_int {
self.0
}

/// Represents the SIGALRM signal.
///
/// On Unix systems this signal is sent when a real-time timer has expired.
/// By default, the process is terminated by this signal.
pub fn alarm() -> Self {
pub const fn alarm() -> Self {
Self(libc::SIGALRM)
}

/// Represents the SIGCHLD signal.
///
/// On Unix systems this signal is sent when the status of a child process
/// has changed. By default, this signal is ignored.
pub fn child() -> Self {
pub const fn child() -> Self {
Self(libc::SIGCHLD)
}

/// Represents the SIGHUP signal.
///
/// On Unix systems this signal is sent when the terminal is disconnected.
/// By default, the process is terminated by this signal.
pub fn hangup() -> Self {
pub const fn hangup() -> Self {
Self(libc::SIGHUP)
}

Expand All @@ -134,23 +134,23 @@ impl SignalKind {
target_os = "netbsd",
target_os = "openbsd"
))]
pub fn info() -> Self {
pub const fn info() -> Self {
Self(libc::SIGINFO)
}

/// Represents the SIGINT signal.
///
/// On Unix systems this signal is sent to interrupt a program.
/// By default, the process is terminated by this signal.
pub fn interrupt() -> Self {
pub const fn interrupt() -> Self {
Self(libc::SIGINT)
}

/// Represents the SIGIO signal.
///
/// On Unix systems this signal is sent when I/O operations are possible
/// on some file descriptor. By default, this signal is ignored.
pub fn io() -> Self {
pub const fn io() -> Self {
Self(libc::SIGIO)
}

Expand All @@ -159,7 +159,7 @@ impl SignalKind {
/// On Unix systems this signal is sent when the process attempts to write
/// to a pipe which has no reader. By default, the process is terminated by
/// this signal.
pub fn pipe() -> Self {
pub const fn pipe() -> Self {
Self(libc::SIGPIPE)
}

Expand All @@ -168,39 +168,39 @@ impl SignalKind {
/// On Unix systems this signal is sent to issue a shutdown of the
/// process, after which the OS will dump the process core.
/// By default, the process is terminated by this signal.
pub fn quit() -> Self {
pub const fn quit() -> Self {
Self(libc::SIGQUIT)
}

/// Represents the SIGTERM signal.
///
/// On Unix systems this signal is sent to issue a shutdown of the
/// process. By default, the process is terminated by this signal.
pub fn terminate() -> Self {
pub const fn terminate() -> Self {
Self(libc::SIGTERM)
}

/// Represents the SIGUSR1 signal.
///
/// On Unix systems this is a user defined signal.
/// By default, the process is terminated by this signal.
pub fn user_defined1() -> Self {
pub const fn user_defined1() -> Self {
Self(libc::SIGUSR1)
}

/// Represents the SIGUSR2 signal.
///
/// On Unix systems this is a user defined signal.
/// By default, the process is terminated by this signal.
pub fn user_defined2() -> Self {
pub const fn user_defined2() -> Self {
Self(libc::SIGUSR2)
}

/// Represents the SIGWINCH signal.
///
/// On Unix systems this signal is sent when the terminal window is resized.
/// By default, this signal is ignored.
pub fn window_change() -> Self {
pub const fn window_change() -> Self {
Self(libc::SIGWINCH)
}
}
Expand Down

0 comments on commit ba93b28

Please sign in to comment.