It doesn't make sense to me: compiler tells the lifetimes are different but mentions the same lifetime requirements both times (cannot infer an appropriate lifetime for lifetime parameter in function call due to conflicting requirements [E0495] error).
How cloning something affects whether it lives long enough or doesn't?
The real error is "the trait (Fn) is not implemented for the type (closure)": the way the closure is defined, it can only be called once. handlers::get_records consumes the Arc, so if you don't clone it before passing it in, you can't call the closure multiple times.
You might want to consider making get_records take an &Mutex<Connection> instead of an Arc<Mutex<Connection>>.
This. I don't see much of a need to have any of the code in handlers or afterwards be aware that Connection is stored in an Arc.
However, it might also be wise to use an RwLock instead of Mutex, as I believe these handler functions can be called in parallel. You don't always need mutable access, looks like, but mutex synchronization means that only one thread can access Connection at a time, regardless of whether it's reading or writing..
Is this for<'r, 'r, 'r> core::ops::Fn<(&'r mut iron::request::Request<'r, 'r>,)> syntax documented anywhere? Specifically, I don't think I saw for<'r... before
the way the closure is defined, it can only be called once
How does one figure it out from the error?..
I'm actually aware of the suggested solution, sorry for not poiting it out earlier. I'm just trying to understand details and how to read the error messages: it bothers me I'm unable to understand and fix such errors w/o help from other people. /cc @DroidLogician
It's because the function you pass to Router is Fn(...) -> ..., i.e. a shared immutable function. This means that any variables it closes over are accessed as &-references, so sdb_ inside closure is &Arc<...> and not Arc<...>. This is needed because router invokes that function multiple times. Otherwise, first call to closure would consume your Arc instance, and following calls will have no Arc to operate on. Think about closure as of object with invoke method, implicit self and some hidden fields.
UPD: try passing &Connection or &mut Connection to your handler funcs, and protect it with RWLock. This way you won't need excess Arc clones.
One thing that is still not clear to me is how to figure it out from docs. All they say is it needs a Handler. How to know Handler is supposed to be Fn and not FnOnce?
That's true, and look for F, it required Fn, but with mutable request. Handler still not mut during handling, but in your case you've tried to take away owning for its referenced mutex.
for <'a> is the only syntax without docs. It's a "higher ranked trait bound", and is a very niche kind of thing. There's an RFC that describes it. I haven't figured out how/when to put it in the docs.