These are chat archives for rust-lang/rust

Jul 2017
Jul 29 2017 12:14 UTC
Hi! Is there a way to have reference to non-Sync data inside struct that has to implement Sync? I tried Arc<Mutex<Data>>, but Mutex<T> still requires T to be Sync.
Some context: I'm trying to create caching middleware for Iron, and middleware in Iron has to satisfy Send + Sync.
Jul 29 2017 12:40 UTC
Specifically, iron::Response does not seem to implement Sync.
David Harvey-Macaulay
Jul 29 2017 13:09 UTC
@Rogach You can wrap the non-Sync data inside another struct and implement Send and Sync on it yourself - example. The caveat is that you're responsible for maintaining the thread safety yourself.
N.B. the example compiles but does not execute as intended because of lack of thread safety. I think the Rc is deallocated before the thread has a chance to print its value.
Jul 29 2017 13:11 UTC
@alteous - Thanks! I'll look into it.
Actually, seems that iron::Response can't even do .clone(), so the whole affair is pointless. I'll just use Vec<u8>, which is quite comfortably Send + Sync.