Replies: 4 comments
-
see https://doc.rust-lang.org/std/ops/trait.FnOnce.html Since both Fn and FnMut are subtraits of FnOnce, any instance of Fn or FnMut can be used where a FnOnce is expected. so, if you expect the param to be |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reply!
That's what I mentioned at the beginning of my question. My point is why require |
Beta Was this translation helpful? Give feedback.
-
I don't specifically remember but would a fun exercise to change it to |
Beta Was this translation helpful? Give feedback.
-
maybe related: hyperium/hyper#3223 hyper just changed service
|
Beta Was this translation helpful? Give feedback.
-
Hello, I was wondering why the handler trait, which is a subtrait of
Clone
is implemented forFnOnce
.To my understanding implementing
FnOnce
give users more flexibility, as it can also acceptFnMut
andFn
.So we can use it for closure that can mutably capture their environment. But as it also requires
Clone
, we can't mutably capture the environment:playground
So what is the point to implement
FnOnce
if we can't really mutably capture the environment? Why not implement only forFn
?So they might be another reason, but I can't figure it out, if you could please enlighten me.
Beta Was this translation helpful? Give feedback.
All reactions