Skip to main content

ResultSeverityExt

Trait ResultSeverityExt 

Source
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§

Source

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

Source

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§

Source

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)

Source

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)

Source

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)

Source

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)

Source

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)

Source

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", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T, E> ResultSeverityExt<T, E> for Result<T, E>
where E: Into<BevyError>,

Source§

fn with_severity(self, severity: Severity) -> Result<T, BevyError>

Source§

fn map_severity(self, f: impl FnOnce(&E) -> Severity) -> Result<T, BevyError>

Implementors§