renderdoc/
error.rs

1//! Common library error types.
2
3use std::fmt::{self, Display, Formatter};
4
5/// Errors that can occur with the RenderDoc in-application API.
6#[derive(Debug)]
7pub struct Error(ErrorKind);
8
9impl Error {
10    pub(crate) fn library(cause: libloading::Error) -> Self {
11        Error(ErrorKind::Library(cause))
12    }
13
14    pub(crate) fn symbol(cause: libloading::Error) -> Self {
15        Error(ErrorKind::Symbol(cause))
16    }
17
18    pub(crate) fn no_compatible_api() -> Self {
19        Error(ErrorKind::NoCompatibleApi)
20    }
21
22    pub(crate) fn launch_replay_ui() -> Self {
23        Error(ErrorKind::LaunchReplayUi)
24    }
25}
26
27impl Display for Error {
28    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
29        match self.0 {
30            ErrorKind::Library(_) => write!(f, "Unable to load RenderDoc shared library"),
31            ErrorKind::Symbol(_) => write!(f, "Unable to find `RENDERDOC_GetAPI` symbol"),
32            ErrorKind::NoCompatibleApi => write!(f, "Library could not provide compatible API"),
33            ErrorKind::LaunchReplayUi => write!(f, "Failed to launch replay UI"),
34        }
35    }
36}
37
38impl std::error::Error for Error {
39    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
40        match self.0 {
41            ErrorKind::Library(ref e) | ErrorKind::Symbol(ref e) => Some(e),
42            _ => None,
43        }
44    }
45}
46
47#[derive(Debug)]
48enum ErrorKind {
49    Library(libloading::Error),
50    Symbol(libloading::Error),
51    NoCompatibleApi,
52    LaunchReplayUi,
53}