pub struct LifespanHooks {
pub on_startup: Option<StartupHook>,
pub on_shutdown: Option<ShutdownHook>,
}Expand description
Lifecycle hooks for server startup and shutdown.
These hooks allow custom initialization and cleanup logic to run at well-defined points in the server lifecycle:
on_startup: Called before the server starts accepting connectionson_shutdown: Called when the server is shutting down
§Example
ⓘ
use fastmcp_rust::prelude::*;
Server::new("demo", "1.0.0")
.on_startup(|| {
println!("Initializing...");
// Initialize database, caches, etc.
Ok(())
})
.on_shutdown(|| {
println!("Cleaning up...");
// Close connections, flush buffers, etc.
})
.run_stdio();Fields§
§on_startup: Option<StartupHook>Hook called before the server starts accepting connections.
on_shutdown: Option<ShutdownHook>Hook called when the server is shutting down.
Implementations§
Source§impl LifespanHooks
impl LifespanHooks
Trait Implementations§
Source§impl Default for LifespanHooks
impl Default for LifespanHooks
Source§fn default() -> LifespanHooks
fn default() -> LifespanHooks
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for LifespanHooks
impl !RefUnwindSafe for LifespanHooks
impl Send for LifespanHooks
impl !Sync for LifespanHooks
impl Unpin for LifespanHooks
impl !UnwindSafe for LifespanHooks
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).