pub trait RecoverableError: Debug + Display {
// Provided method
fn is_recoverable(&self) -> bool { ... }
}Expand description
A surface-lifecycle error that can optionally signal whether it’s worth retrying.
Presenter::SurfaceError is a per-implementation associated type: softbuffer’s error enum
has no Lost/Outdated/Timeout discrimination the way wgpu::SurfaceError does, so today’s
only backend (SoftwareRenderer) has no structured way to say “this specific failure is
fatal, don’t bother retrying.” is_recoverable is that hook: a
presenter with real error categories can override it to return false for a truly fatal
failure, while every presenter that doesn’t need the distinction (including every backend that
exists in this crate today) can implement this trait with an empty body and inherit the
default true.
Not blanket-implemented for every Debug + Display type: that would make it
impossible for any concrete error type to override is_recoverable at
all (a specific impl would conflict with the blanket one), defeating the point of the trait.
Instead, each SurfaceError type needs one explicit (and usually empty) impl RecoverableError for ... block: see retroglyph_software’s SurfaceError for the minimal
case that just inherits the default.
§Examples
use core::fmt;
use retroglyph_window::RecoverableError;
#[derive(Debug)]
enum MySurfaceError {
Init,
Lost,
}
impl fmt::Display for MySurfaceError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Init => write!(f, "surface init failed"),
Self::Lost => write!(f, "surface lost"),
}
}
}
impl RecoverableError for MySurfaceError {
fn is_recoverable(&self) -> bool {
// Init failures are fatal; a lost surface may come back.
matches!(self, Self::Lost)
}
}
assert!(!MySurfaceError::Init.is_recoverable());
assert!(MySurfaceError::Lost.is_recoverable());Provided Methods§
Sourcefn is_recoverable(&self) -> bool
fn is_recoverable(&self) -> bool
Whether this error represents a transient failure worth retrying, as opposed to a fatal one.
Defaults to true: absent any structured error categorization, every failure is treated
as potentially transient, matching the generic consecutive-failure recovery heuristic
winit::run::present_failure_action already applies. Override to return false only for
an error variant known to be unrecoverable regardless of retries (e.g. a wgpu::SurfaceError ::Lost variant that persists until the surface is fully rebuilt from a different code
path than a simple retry).