You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use a similar pattern to the fn_handler proc macro in a crate that I'm working on and didn't want to require the user to annotate the function with a proc macro. Instead, I use this pattern:
You might need to add a lifetime annotation into the future generic, but this might let you skip the need for impl SalvoHandler. SalvoHandler would be directly impl for the Handler struct, which you can still treat as Box<dyn SalvoHandler>. To pass the handlers into the router, you would just accept impl into<Handler>.
However, I would suggest just sticking with a single type generic over the future, forcing req, resp, and depot to be part of every handler. It might be a bit ceremonious in boiler plate, but would be easy to copy-paste and forces consistency within a given codebase.
The text was updated successfully, but these errors were encountered:
I tried to use simple proxy traits and macros to implement what salvo proc macro, but failed because, after multiple proxies, there was a problem with the lifetime judgment, and rustc does not recognize such operations.
I studied the realization of bevy, and it can be achieved, but I think it’s more complicated
Function pointers may be an option, but not sure at this time
I use a similar pattern to the
fn_handler
proc macro in a crate that I'm working on and didn't want to require the user to annotate the function with a proc macro. Instead, I use this pattern:You might need to add a lifetime annotation into the future generic, but this might let you skip the need for
impl SalvoHandler
.SalvoHandler
would be directly impl for the Handler struct, which you can still treat asBox<dyn SalvoHandler>
. To pass the handlers into the router, you would just acceptimpl into<Handler>
.However, I would suggest just sticking with a single type generic over the future, forcing req, resp, and depot to be part of every handler. It might be a bit ceremonious in boiler plate, but would be easy to copy-paste and forces consistency within a given codebase.
The text was updated successfully, but these errors were encountered: