Skip to main content

Receiver

Struct Receiver 

Source
pub struct Receiver(/* private fields */);
Expand description

Receives UNIX signals forwarded through a Signals channel.

Obtained via Signals::subscribe. Use listen to block until a signal arrives, or try_listen to poll without blocking.

Implementations§

Source§

impl Receiver

Source

pub fn listen(&self) -> Result<Signal, SignalError>

Blocks until a signal is received and returns it.

§Examples
use signal_msg::Signals;

let signals = Signals::new().expect("signal setup failed");
let receiver = signals.subscribe();
match receiver.listen() {
    Ok(sig) => println!("received: {}", sig),
    Err(e)  => eprintln!("channel closed: {}", e),
}
§Errors

Returns SignalError::Disconnected if the backing Signals handle has been dropped and no further signals can arrive.

Examples found in repository?
examples/demo.rs (line 7)
3fn main() {
4    let signals = Signals::new().expect("failed to create signal handler");
5    let receiver = signals.subscribe();
6    println!("Waiting for a signal...");
7    match receiver.listen() {
8        Ok(sig) => println!("\nGot signal: {}", sig),
9        Err(e) => eprintln!("\nError: {}", e),
10    }
11}
Source

pub fn try_listen(&self) -> Result<Option<Signal>, SignalError>

Returns the next signal if one is immediately available, or None if the channel is currently empty.

Unlike listen, this method never blocks.

§Examples
use signal_msg::Signals;

let signals = Signals::new().expect("signal setup failed");
let receiver = signals.subscribe();
match receiver.try_listen() {
    Ok(Some(sig)) => println!("got signal: {}", sig),
    Ok(None)      => println!("no signal pending"),
    Err(e)        => eprintln!("channel closed: {}", e),
}
§Errors

Returns SignalError::Disconnected if the backing Signals handle has been dropped and no further signals can arrive.

Trait Implementations§

Source§

impl Debug for Receiver

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 = Infallible

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.