Skip to main content

trillium_aws_lambda/
context.rs

1use lamedh_runtime::Context;
2use std::ops::Deref;
3
4pub(crate) struct LambdaContext(Context);
5impl LambdaContext {
6    pub fn new(context: Context) -> Self {
7        Self(context)
8    }
9}
10
11impl Deref for LambdaContext {
12    type Target = Context;
13
14    fn deref(&self) -> &Self::Target {
15        &self.0
16    }
17}
18
19/// Provides access to the aws lambda context for [`trillium::Conn`].
20///
21/// See [`lamedh_runtime::Context`] for more details on the data available
22/// on this struct.
23pub trait LambdaConnExt {
24    /// returns the [`lamedh_runtime::Context`] for this conn
25    fn lambda_context(&self) -> &Context;
26}
27
28impl LambdaConnExt for trillium::Conn {
29    fn lambda_context(&self) -> &Context {
30        self.state::<LambdaContext>()
31            .expect("lambda context should always be set inside of a lambda server")
32    }
33}