use std::io; use std::io::prelude::*; use std::sync::{Arc, Mutex}; pub struct LockedIO(Arc>); impl LockedIO { pub fn from(inner: Arc>) -> LockedIO { LockedIO(inner) } } impl Clone for LockedIO { fn clone(&self) -> LockedIO { LockedIO(self.0.clone()) } } impl io::Write for LockedIO { fn write(&mut self, buf: &[u8]) -> io::Result { let mut inner = self.0.lock().unwrap(); // TODO: make safer inner.write(buf) } fn flush(&mut self) -> io::Result<()> { let mut inner = self.0.lock().unwrap(); // TODO: make safer inner.flush() } } impl io::Read for LockedIO { fn read(&mut self, buf: &mut [u8]) -> io::Result { let mut inner = self.0.lock().unwrap(); // TODO: make safer inner.read(buf) } }