signal
import std::process::signal; · source
Types
Signal
type struct Signal {
value: SigNo;
static new(value: SigNo) -> Signal;
static from_i32(value: i32) -> Signal;
as_i32(&this) -> i32;
static hangup() -> Signal;
static interrupt() -> Signal;
static quit() -> Signal;
static illegal() -> Signal;
static trap() -> Signal;
static abort() -> Signal;
static bus() -> Signal;
static floating_point() -> Signal;
static kill() -> Signal;
static user1() -> Signal;
static segfault() -> Signal;
static user2() -> Signal;
static pipe() -> Signal;
static alarm() -> Signal;
static terminate() -> Signal;
static child() -> Signal;
static cont() -> Signal;
static stop() -> Signal;
static tty_stop() -> Signal;
}
Signal wraps a SigNo so the compiler catches passing a pid where a signal was expected. The common ones have named constructors, and arbitrary numbers go through from_i32.
Properties
| Property | Type |
|---|---|
value | SigNo |
Constructors
static new(value: SigNo) -> Signal;
static from_i32(value: i32) -> Signal;
static hangup() -> Signal;
static interrupt() -> Signal;
static quit() -> Signal;
static illegal() -> Signal;
static trap() -> Signal;
static abort() -> Signal;
static bus() -> Signal;
static floating_point() -> Signal;
static kill() -> Signal;
static user1() -> Signal;
static segfault() -> Signal;
static user2() -> Signal;
static pipe() -> Signal;
static alarm() -> Signal;
static terminate() -> Signal;
static child() -> Signal;
static cont() -> Signal;
static stop() -> Signal;
static tty_stop() -> Signal;
Methods
as_i32(&this) -> i32;
as_i32(&this) -> i32;Underlying signal number for the libc syscall.
SigNo
type enum SigNo : i32 {
SIGHUP = 1;
SIGINT = 2;
SIGQUIT = 3;
SIGILL = 4;
SIGTRAP = 5;
SIGABRT = 6;
SIGBUS = 7;
SIGFPE = 8;
SIGKILL = 9;
SIGUSR1 = 10;
SIGSEGV = 11;
SIGUSR2 = 12;
SIGPIPE = 13;
SIGALRM = 14;
SIGTERM = 15;
SIGCHLD = 17;
SIGCONT = 18;
SIGSTOP = 19;
SIGTSTP = 20;
}
implement enum SigNo {
static from_i32(value: i32) -> SigNo;
}
The signal numbers, matching Linux x86-64. from_i32 maps a raw number back onto the enum.
Signal handling — installing a handler with
sigaction— is not modelled here. The moment a program installs handlers it crosses into async-signal safety, reentrant allocation, and interaction with every other stdlib primitive; that is a separate design problem.
Variants
| Variant |
|---|
SIGHUP = 1 |
SIGINT = 2 |
SIGQUIT = 3 |
SIGILL = 4 |
SIGTRAP = 5 |
SIGABRT = 6 |
SIGBUS = 7 |
SIGFPE = 8 |
SIGKILL = 9 |
SIGUSR1 = 10 |
SIGSEGV = 11 |
SIGUSR2 = 12 |
SIGPIPE = 13 |
SIGALRM = 14 |
SIGTERM = 15 |
SIGCHLD = 17 |
SIGCONT = 18 |
SIGSTOP = 19 |
SIGTSTP = 20 |
Constructors
static from_i32(value: i32) -> SigNo;
type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
type struct Signal {
value: SigNo;
}POSIX signal numbers.
Signal.value: SigNotype enum SigNo : i32 {
SIGHUP = 1;
SIGINT = 2;
SIGQUIT = 3;
SIGILL = 4;
SIGTRAP = 5;
SIGABRT = 6;
SIGBUS = 7;
SIGFPE = 8;
SIGKILL = 9;
SIGUSR1 = 10;
// … 9 more
}static name(param: Type) -> Ret { ... }A method that belongs to the type rather than an instance, called as Type::name(..). For structs, static new(..) returning a struct literal is the idiomatic constructor.
static Signal::new(value: SigNo) -> Signal(parameter) value: SigNostatic Signal::from_i32(value: i32) -> Signal(parameter) value: i32Signal::as_i32(&this) -> i32Underlying signal number for the libc syscall.
&this
mut &this
thisThe receiver of a method. Its first parameter declares how the method takes it: &this borrows read-only, mut &this borrows exclusively, and this / mut this move the value in and consume it. In the body, this.field reaches the members.
static Signal::hangup() -> Signalstatic Signal::interrupt() -> Signalstatic Signal::quit() -> Signalstatic Signal::illegal() -> Signalstatic Signal::trap() -> Signalstatic Signal::abort() -> Signalstatic Signal::bus() -> Signalstatic Signal::floating_point() -> Signalstatic Signal::kill() -> Signalstatic Signal::user1() -> Signalstatic Signal::segfault() -> Signalstatic Signal::user2() -> Signalstatic Signal::pipe() -> Signalstatic Signal::alarm() -> Signalstatic Signal::terminate() -> Signalstatic Signal::child() -> Signalstatic Signal::cont() -> Signalstatic Signal::stop() -> Signalstatic Signal::tty_stop() -> Signaltype enum Name {
Unit,
Payload(T),
Named { x: i32 },
}An algebraic data type. Variants may be bare or carry a tuple or struct payload, and a match on an enum must cover every variant. Name::Variant names a variant; methods are added with implement enum Name { ... }.
type enum SigNo : i32 {
SIGHUP = 1;
SIGINT = 2;
SIGQUIT = 3;
SIGILL = 4;
SIGTRAP = 5;
SIGABRT = 6;
SIGBUS = 7;
SIGFPE = 8;
SIGKILL = 9;
SIGUSR1 = 10;
// … 9 more
}SigNo::SIGHUP = 1SigNo::SIGINT = 2SigNo::SIGQUIT = 3SigNo::SIGILL = 4SigNo::SIGTRAP = 5SigNo::SIGABRT = 6SigNo::SIGBUS = 7SigNo::SIGFPE = 8SigNo::SIGKILL = 9SigNo::SIGUSR1 = 10SigNo::SIGSEGV = 11SigNo::SIGUSR2 = 12SigNo::SIGPIPE = 13SigNo::SIGALRM = 14SigNo::SIGTERM = 15SigNo::SIGCHLD = 17SigNo::SIGCONT = 18SigNo::SIGSTOP = 19SigNo::SIGTSTP = 20implement struct Name { ... }
implement trait Trait for Type { ... }
implement u64 { ... }Adds methods to a type outside its declaration. implement struct T (or enum, or a bare primitive) opens an inherent block; implement trait Tr for T supplies a trait's methods for one type. Resolution is at compile time - no dynamic dispatch.
implement enum Name { ... }Names the enum an inherent block extends - the only way to give an enum methods.
language referencestatic SigNo::from_i32(value: i32) -> SigNoimport a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
static SigNo::from_i32(value: i32) -> SigNoSignal.value: SigNostatic Signal::new(value: SigNo) -> Signalstatic Signal::hangup() -> Signalstatic Signal::interrupt() -> Signalstatic Signal::quit() -> Signalstatic Signal::illegal() -> Signalstatic Signal::trap() -> Signalstatic Signal::abort() -> Signalstatic Signal::bus() -> Signalstatic Signal::floating_point() -> Signalstatic Signal::kill() -> Signalstatic Signal::user1() -> Signalstatic Signal::segfault() -> Signalstatic Signal::user2() -> Signalstatic Signal::pipe() -> Signalstatic Signal::alarm() -> Signalstatic Signal::terminate() -> Signalstatic Signal::child() -> Signalstatic Signal::cont() -> Signalstatic Signal::stop() -> Signalstatic Signal::tty_stop() -> SignalSigNo::SIGHUP = 1SigNo::SIGINT = 2SigNo::SIGQUIT = 3SigNo::SIGILL = 4SigNo::SIGTRAP = 5SigNo::SIGABRT = 6SigNo::SIGBUS = 7SigNo::SIGFPE = 8SigNo::SIGKILL = 9SigNo::SIGUSR1 = 10SigNo::SIGSEGV = 11SigNo::SIGUSR2 = 12SigNo::SIGPIPE = 13SigNo::SIGALRM = 14SigNo::SIGTERM = 15SigNo::SIGCHLD = 17SigNo::SIGCONT = 18SigNo::SIGSTOP = 19SigNo::SIGTSTP = 20