Skip to content

Refactor initialization closures into event handler types #1

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:

pubtraitEventHandler<O:Serialize,E:Display,I:LambdaContext>{fninitialize(&mutself) -> Result<(),E>;fnon_event(&mutself,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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions