Skip to content

Refactor initialization closures into event handler types #1

@guyo13

Description

@guyo13

As of version 0.0.1 the DefaultRuntime accepts an initialization function that returns a trait object.
This results in unneeded heap allocation and dynamic dispatch.

Instead, the API should be re-written to allow the compiler to statically determine the types involved.

The user will have to implement an EventHandler trait:

pub trait EventHandler<O: Serialize, E: Display, I: LambdaContext> {
    fn initialize(&mut self) -> Result<(), E>;
    fn on_event(&mut self, event: &str, context: &I) -> Result<O, E>;
}

Types implementing it, perform Lambda instance initialization once inside initialize and event handling inside on_event.
Any resources can be part of the struct implementing the EventHandler trait.

The on_event should take a &str as the event string instead of the previous Option<&str> to simplify users' functions.

Metadata

Metadata

Assignees

Labels

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions