pub trait ResultSeverityExt<T, E>: Sized {
// Required methods
fn with_severity(self, severity: Severity) -> Result<T, BevyError>;
fn map_severity(
self,
f: impl FnOnce(&E) -> Severity,
) -> Result<T, BevyError>;
// Provided methods
fn ignore(self) -> Result<T, BevyError> { ... }
fn trace(self) -> Result<T, BevyError> { ... }
fn info(self) -> Result<T, BevyError> { ... }
fn warn(self) -> Result<T, BevyError> { ... }
fn error(self) -> Result<T, BevyError> { ... }
fn panic(self) -> Result<T, BevyError> { ... }
}Expand description
Extension methods for annotating errors with a Severity.
Required Methods§
Sourcefn with_severity(self, severity: Severity) -> Result<T, BevyError>
fn with_severity(self, severity: Severity) -> Result<T, BevyError>
Overrides the Severity of the error if this result is Err.
This does not change control flow; it only annotates the error.
§Example
fn fallible() -> Result<(), BevyError> {
// This failure is expected in some contexts, so we downgrade its severity.
let _parsed: usize = "I am not a number"
.parse()
.with_severity(Severity::Warning)?;
Ok(())
}For more fine grained control see Result::map_severity
Sourcefn map_severity(self, f: impl FnOnce(&E) -> Severity) -> Result<T, BevyError>
fn map_severity(self, f: impl FnOnce(&E) -> Severity) -> Result<T, BevyError>
Overrides the Severity of the error if this result is Err.
This does not change control flow; it only annotates the error.
§Example
#[derive(Error, Debug)]
pub enum ValidationError {
#[error("Incorrect version")]
IncorrectVersion,
#[error("Syntax error")]
SyntaxError,
}
fn fallible() -> Result<(), BevyError> {
// This failure is expected in some contexts, so we downgrade its severity.
let _parsed: usize = validate("I am not a number")
.map_severity(|e| match e {
ValidationError::IncorrectVersion => Severity::Debug,
ValidationError::SyntaxError => Severity::Error,
})?;
Ok(())
}If you don’t need to inspect the error, use Result::with_severity
Provided Methods§
Sourcefn ignore(self) -> Result<T, BevyError>
fn ignore(self) -> Result<T, BevyError>
Overrides the severity of the error with Severity::Ignore. See Result::with_severity
This is shorthand for self.with_severity(Severity::Ignore)
Sourcefn trace(self) -> Result<T, BevyError>
fn trace(self) -> Result<T, BevyError>
Overrides the severity of the error with Severity::Trace. See Result::with_severity
This is shorthand for self.with_severity(Severity::Trace)
Sourcefn info(self) -> Result<T, BevyError>
fn info(self) -> Result<T, BevyError>
Overrides the severity of the error with Severity::Info. See Result::with_severity
This is shorthand for self.with_severity(Severity::Info)
Sourcefn warn(self) -> Result<T, BevyError>
fn warn(self) -> Result<T, BevyError>
Overrides the severity of the error with Severity::Warning. See Result::with_severity
This is shorthand for self.with_severity(Severity::Warning)
Sourcefn error(self) -> Result<T, BevyError>
fn error(self) -> Result<T, BevyError>
Overrides the severity of the error with Severity::Error. See Result::with_severity
This is shorthand for self.with_severity(Severity::Error)
Sourcefn panic(self) -> Result<T, BevyError>
fn panic(self) -> Result<T, BevyError>
Overrides the severity of the error with Severity::Panic. See Result::with_severity
This is shorthand for self.with_severity(Severity::Panic)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".