//! Helper: A cloneable wrapper for io::Result. //! //! This is all necessary because io::Error doesn't implement `Clone`. use std::{io, sync::Arc}; /// A helper type for a variation on an `io::Error` that we can clone. pub(crate) type ArcIoResult = Result>; /// Extension trait for `Result>` pub(crate) trait ArcIoResultExt { /// Create a new `io::Result` from this `ArcIoResult` /// /// We do this by making a new new io::Error (if necessary) /// with [`wrap_error`]. fn io_result(&self) -> io::Result; } impl ArcIoResultExt for ArcIoResult { fn io_result(&self) -> io::Result { match &self { Ok(r) => Ok(r.clone()), Err(e) => Err(wrap_error(e)), } } } /// Wrap an Arc as a new io::Error. pub(crate) fn wrap_error(e: &Arc) -> io::Error { io::Error::new(e.kind(), Arc::clone(e)) }