cloudflare / workers-rs

Write Cloudflare Workers in 100% Rust via WebAssembly
Apache License 2.0
2.53k stars 269 forks source link

Relax type of callback arguments to Router methods #605

Closed compiler-errors closed 1 month ago

compiler-errors commented 2 months ago

This PR relaxes the type of the callback

func: fn(Request, RouteContext<D>) -> T

into

func: impl Fn(Request, RouteContext<D>) -> T + 'static

which is an argument-position impl trait type (APIT), since I don't see any reason for requiring the passed-in callback is a function pointer, since we're immediately boxing it up and erasing the type.

Specifically, this ensures that you can pass a (currently nightly-only) async closure (async ||), which currently does not support being coerced to a fn ptr type. I'd like to avoid needing to implement that functionality that if possible.