pub trait ErrorHelper {
type Error;
// Required method
fn err(&self, msg: impl Into<String>) -> Self::Error;
// Provided methods
fn fail<T>(&self, msg: impl Into<String>) -> Result<T, Self::Error> { ... }
fn unwrap<T>(
&self,
opt: Option<T>,
msg: impl Into<String>,
) -> Result<T, Self::Error> { ... }
fn assert(&self, b: bool) -> Result<(), Self::Error> { ... }
fn ok<T, E>(
&self,
_res: Result<T, E>,
msg: impl Into<String>,
) -> Result<T, Self::Error>
where E: Error + 'static { ... }
}
Expand description
Helper trait for re-use among our many conversion tree-walkers.
Each implementer will generally have some internal state to report upon failure,
which it can inject in the implementation-required err
method.
The fail
method, provided by default, simply returns the err
value.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn assert(&self, b: bool) -> Result<(), Self::Error>
fn assert(&self, b: bool) -> Result<(), Self::Error>
Assert boolean condition b
. Returns through self.fail
if not.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.