Since there isn't enough code provided for me to reproduce your issue, I've made this:
use std::cell::Cell;trait Middleware: Sync {}struct Unsharable(Cell<bool>);impl Middleware for Unsharable {}fn main() {}
which has the same error:
error: the trait bound `std::cell::Cell<bool>: std::marker::Sync` is not satisfied [E0277]impl Middleware for Unsharable {} ^~~~~~~~~~help: run `rustc --explain E0277` to see a detailed explanationnote: `std::cell::Cell<bool>` cannot be shared between threads safelynote: required because it appears within the type `Unsharable`note: required by `Middleware`
You can solve the problem by changing the type to make it cross-thread compatible:
use std::sync::Mutex;struct Sharable(Mutex<Unsharable>);impl Middleware for Sharable {}
Note that Rust has done a very good thing for you: it prevented you from using a type that is unsafe to be called in multiple threads.
In writing my tests, I'd like to be able to inject a connection into the request so that I can wrap the entire test case in a transaction (even if there is more than one request in the test case).
I'd suggest that it's possible an architectural change would be even better. Separate the domains of "web framework" from your "database". The authors of Growing Object-Oriented Software, Guided by Tests (a highly recommended book) advocate for this style.
Pull apart your code such that there is a method that simply accepts some type that can start / end a transaction, write the interesting stuff there, and test it thoroughly. Then have just enough glue code in the web layer to create a transaction object, then call the next layer down.