diff --git a/vortex-error/src/ext.rs b/vortex-error/src/ext.rs new file mode 100644 index 00000000000..a1e2ee5befc --- /dev/null +++ b/vortex-error/src/ext.rs @@ -0,0 +1,24 @@ +use crate::VortexResult; + +/// Extension trait for VortexResult +pub trait ResultExt: private::Sealed { + /// Flatten a nested [`VortexResult`]. Helper function until is stabilized. + fn flatten(self) -> VortexResult; +} + +mod private { + use crate::VortexResult; + + pub trait Sealed {} + + impl Sealed for VortexResult> {} +} + +impl ResultExt for VortexResult> { + fn flatten(self) -> VortexResult { + match self { + Ok(Ok(v)) => Ok(v), + Ok(Err(e)) | Err(e) => Err(e), + } + } +} diff --git a/vortex-error/src/lib.rs b/vortex-error/src/lib.rs index 5e67aa7cef7..61fa2de1675 100644 --- a/vortex-error/src/lib.rs +++ b/vortex-error/src/lib.rs @@ -7,6 +7,8 @@ #[cfg(feature = "python")] pub mod python; +mod ext; + use std::backtrace::Backtrace; use std::borrow::Cow; use std::convert::Infallible; @@ -16,6 +18,8 @@ use std::num::TryFromIntError; use std::ops::Deref; use std::{env, fmt, io}; +pub use ext::*; + /// A string that can be used as an error message. #[derive(Debug)] pub struct ErrString(Cow<'static, str>);