pub trait LifecycleHook: Send + Sync {
// Provided methods
fn before_request<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn after_response<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 ResponseContext,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_mock_created<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 MockLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_mock_updated<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 MockLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_mock_deleted<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 MockLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_mock_state_changed<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 MockLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_startup<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 ServerLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_shutdown<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 ServerLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
Comprehensive lifecycle hook trait
Implement this trait to hook into various lifecycle events in MockForge. All methods have default no-op implementations, so you only need to implement the hooks you care about.
Provided Methods§
Sourcefn before_request<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn before_request<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 RequestContext,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called before a request is processed
This hook is called after the request is received but before it’s matched against mocks or processed. You can use this to:
- Log requests
- Modify request headers
- Add request metadata
- Perform authentication checks
Sourcefn after_response<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 ResponseContext,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn after_response<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 ResponseContext,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called after a response is generated
This hook is called after the response is generated but before it’s sent to the client. You can use this to:
- Log responses
- Modify response headers
- Add response metadata
- Perform response validation
Sourcefn on_mock_created<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 MockLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_mock_created<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 MockLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when a mock is created
Sourcefn on_mock_updated<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 MockLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_mock_updated<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 MockLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when a mock is updated
Sourcefn on_mock_deleted<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 MockLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_mock_deleted<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 MockLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when a mock is deleted
Sourcefn on_mock_state_changed<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 MockLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_mock_state_changed<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 MockLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when a mock is enabled or disabled
Sourcefn on_startup<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 ServerLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_startup<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 ServerLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when the server starts up
Sourcefn on_shutdown<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 ServerLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_shutdown<'life0, 'life1, 'async_trait>(
&'life0 self,
_event: &'life1 ServerLifecycleEvent,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called when the server shuts down