pub trait SnapStartResource: Send + Sync {
// Provided methods
fn before_snapshot(
&self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + '_>> { ... }
fn after_restore(
&self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + '_>> { ... }
}Expand description
A resource that needs custom logic around the SnapStart snapshot/restore boundary.
Implement this trait on types holding snapshot-sensitive state (connection
pools, credentials, cached DNS, etc.) and register them with
Runtime::register_snapstart_resource.
Both methods default to a no-op, so implementors only override the hook they need. See the module docs for ordering semantics.
Each method returns a BoxFuture (rather than being an async fn) so the
trait stays object-safe and can be stored as dyn SnapStartResource without
pulling in the async-trait crate. Implementations wrap their body in
Box::pin(async move { .. }).
Provided Methods§
Sourcefn before_snapshot(
&self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + '_>>
fn before_snapshot( &self, ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + '_>>
Called before the VM snapshot is taken.
Use this to release resources that will not survive the snapshot, such as open connections or buffered data.
Runs in reverse registration order (LIFO) across all registered resources.
Sourcefn after_restore(
&self,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + '_>>
fn after_restore( &self, ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Send + Sync>>> + Send + '_>>
Called after the VM is restored from a snapshot.
Use this to re-establish resources released in
before_snapshot, refresh credentials, or
regenerate values that must be unique per execution environment.
Runs in registration order (FIFO) across all registered resources. If
this returns an error, the runtime reports it to Lambda via
/restore/error and the runtime exits.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".