1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! A lost device as a typed value rather than a message string.
/// Why the backend reported the device lost.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum DeviceLossReason {
/// The device was destroyed on purpose, by the application or on teardown.
Destroyed,
/// The driver, adapter or browser dropped the device: a reset, a removed
/// adapter, a timeout or an unrecoverable fault.
Unknown,
}
impl DeviceLossReason {
/// A stable lowercase name for logs and the browser event.
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Destroyed => "destroyed",
Self::Unknown => "unknown",
}
}
}
/// The recorded cause of a device loss.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DeviceLoss {
/// Classified reason.
pub reason: DeviceLossReason,
/// Backend-supplied detail, possibly empty.
pub message: String,
}
impl DeviceLoss {
/// Whether opening a fresh device and rebuilding every resource from the
/// scene is expected to succeed.
///
/// A device the application destroyed is gone by intent; any other loss
/// leaves the adapter available to open again.
#[must_use]
pub const fn recoverable(&self) -> bool {
match self.reason {
DeviceLossReason::Destroyed => false,
DeviceLossReason::Unknown => true,
}
}
}
#[cfg(test)]
#[path = "device_loss_tests.rs"]
mod tests;