pub struct SignalHook { /* private fields */ }
Expand description
Hook for a signal, the hook is removed when the object is dropped.
Implementations§
Source§impl SignalHook
impl SignalHook
Sourcepub fn new(
signal_name: &str,
callback: impl SignalCallback + 'static,
) -> Result<Self, ()>
pub fn new( signal_name: &str, callback: impl SignalCallback + 'static, ) -> Result<Self, ()>
Hook a signal.
§Arguments
-
signal_name
- The signal to hook (wildcard*
is allowed). -
callback
- A function or a struct that implements SignalCallback, the callback method of the trait will be called when the signal is fired.
§Panics
Panics if the method is not called from the main Weechat thread.
§Example
let signal_hook = SignalHook::new(
"buffer_switch",
|_weechat: &Weechat, _signal_name: &str, data: Option<SignalData>| {
if let Some(data) = data {
match data {
SignalData::Buffer(buffer) => {
buffer.print("Switched buffer")
}
_ => (),
}
}
ReturnCode::Ok
},
);
Auto Trait Implementations§
impl Freeze for SignalHook
impl !RefUnwindSafe for SignalHook
impl !Send for SignalHook
impl !Sync for SignalHook
impl Unpin for SignalHook
impl !UnwindSafe for SignalHook
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more