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/**
20Provides access to the aws lambda context for [`trillium::Conn`].
21
22See [`lamedh_runtime::Context`] for more details on the data available
23on this struct.
24*/
25pub trait LambdaConnExt {
26    /// returns the [`lamedh_runtime::Context`] for this conn
27    fn lambda_context(&self) -> &Context;
28}
29
30impl LambdaConnExt for trillium::Conn {
31    fn lambda_context(&self) -> &Context {
32        self.state::<LambdaContext>()
33            .expect("lambda context should always be set inside of a lambda server")
34    }
35}