pub struct SignalHandler { /* private fields */ }Expand description
Handles SIGINT signals for graceful shutdown.
SignalHandler registers a handler for SIGINT that sets an internal flag
when triggered. The main loop can check this flag using is_shutdown_requested()
without blocking.
§Thread Safety
SignalHandler is thread-safe and can be cloned to share across threads.
The underlying shutdown flag uses atomic operations.
§Example
let handler = SignalHandler::new()?;
// In main loop
loop {
if handler.is_shutdown_requested() {
// Clean up and exit
break;
}
// Continue processing
}Implementations§
Source§impl SignalHandler
impl SignalHandler
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Creates a new SignalHandler and registers the SIGINT handler.
The handler will set an internal flag when SIGINT is received (e.g., when
the user presses Ctrl+C). This flag can be checked using is_shutdown_requested().
§Errors
Returns an error if the signal handler cannot be registered.
Sourcepub fn is_shutdown_requested(&self) -> bool
pub fn is_shutdown_requested(&self) -> bool
Checks if a shutdown has been requested (non-blocking).
Returns true if SIGINT has been received since the handler was created,
false otherwise.
This method is safe to call from any thread and does not block.
Trait Implementations§
Source§impl Clone for SignalHandler
impl Clone for SignalHandler
Source§fn clone(&self) -> SignalHandler
fn clone(&self) -> SignalHandler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SignalHandler
impl RefUnwindSafe for SignalHandler
impl Send for SignalHandler
impl Sync for SignalHandler
impl Unpin for SignalHandler
impl UnwindSafe for SignalHandler
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more