Browse Source

eframe: Remove dependency on `thiserror` (#4483)

Less dependencies => faster compile times

* Part of https://github.com/emilk/egui/issues/4481
pull/4485/head
Emil Ernerfeldt 6 months ago
committed by GitHub
parent
commit
059218d954
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      Cargo.lock
  2. 1
      crates/eframe/Cargo.toml
  3. 99
      crates/eframe/src/lib.rs

1
Cargo.lock

@ -1203,7 +1203,6 @@ dependencies = [
"ron", "ron",
"serde", "serde",
"static_assertions", "static_assertions",
"thiserror",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-futures", "wasm-bindgen-futures",
"web-sys", "web-sys",

1
crates/eframe/Cargo.toml

@ -134,7 +134,6 @@ log.workspace = true
parking_lot.workspace = true parking_lot.workspace = true
raw-window-handle.workspace = true raw-window-handle.workspace = true
static_assertions = "1.1.0" static_assertions = "1.1.0"
thiserror.workspace = true
web-time.workspace = true web-time.workspace = true
# Optional dependencies # Optional dependencies

99
crates/eframe/src/lib.rs

@ -331,37 +331,112 @@ pub fn run_simple_native(
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/// The different problems that can occur when trying to run `eframe`. /// The different problems that can occur when trying to run `eframe`.
#[derive(thiserror::Error, Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
/// An error from [`winit`]. /// An error from [`winit`].
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
#[error("winit error: {0}")] Winit(winit::error::OsError),
Winit(#[from] winit::error::OsError),
/// An error from [`winit::event_loop::EventLoop`]. /// An error from [`winit::event_loop::EventLoop`].
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
#[error("winit EventLoopError: {0}")] WinitEventLoop(winit::error::EventLoopError),
WinitEventLoop(#[from] winit::error::EventLoopError),
/// An error from [`glutin`] when using [`glow`]. /// An error from [`glutin`] when using [`glow`].
#[cfg(all(feature = "glow", not(target_arch = "wasm32")))] #[cfg(all(feature = "glow", not(target_arch = "wasm32")))]
#[error("glutin error: {0}")] Glutin(glutin::error::Error),
Glutin(#[from] glutin::error::Error),
/// An error from [`glutin`] when using [`glow`]. /// An error from [`glutin`] when using [`glow`].
#[cfg(all(feature = "glow", not(target_arch = "wasm32")))] #[cfg(all(feature = "glow", not(target_arch = "wasm32")))]
#[error("Found no glutin configs matching the template: {0:?}. Error: {1:?}")]
NoGlutinConfigs(glutin::config::ConfigTemplate, Box<dyn std::error::Error>), NoGlutinConfigs(glutin::config::ConfigTemplate, Box<dyn std::error::Error>),
/// An error from [`glutin`] when using [`glow`]. /// An error from [`glutin`] when using [`glow`].
#[cfg(feature = "glow")] #[cfg(feature = "glow")]
#[error("egui_glow: {0}")] OpenGL(egui_glow::PainterError),
OpenGL(#[from] egui_glow::PainterError),
/// An error from [`wgpu`]. /// An error from [`wgpu`].
#[cfg(feature = "wgpu")] #[cfg(feature = "wgpu")]
#[error("WGPU error: {0}")] Wgpu(egui_wgpu::WgpuError),
Wgpu(#[from] egui_wgpu::WgpuError), }
impl std::error::Error for Error {}
#[cfg(not(target_arch = "wasm32"))]
impl From<winit::error::OsError> for Error {
#[inline]
fn from(err: winit::error::OsError) -> Self {
Self::Winit(err)
}
}
#[cfg(not(target_arch = "wasm32"))]
impl From<winit::error::EventLoopError> for Error {
#[inline]
fn from(err: winit::error::EventLoopError) -> Self {
Self::WinitEventLoop(err)
}
}
#[cfg(all(feature = "glow", not(target_arch = "wasm32")))]
impl From<glutin::error::Error> for Error {
#[inline]
fn from(err: glutin::error::Error) -> Self {
Self::Glutin(err)
}
}
#[cfg(feature = "glow")]
impl From<egui_glow::PainterError> for Error {
#[inline]
fn from(err: egui_glow::PainterError) -> Self {
Self::OpenGL(err)
}
}
#[cfg(feature = "wgpu")]
impl From<egui_wgpu::WgpuError> for Error {
#[inline]
fn from(err: egui_wgpu::WgpuError) -> Self {
Self::Wgpu(err)
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
#[cfg(not(target_arch = "wasm32"))]
Self::Winit(err) => {
write!(f, "winit error: {err}")
}
#[cfg(not(target_arch = "wasm32"))]
Self::WinitEventLoop(err) => {
write!(f, "winit EventLoopError: {err}")
}
#[cfg(all(feature = "glow", not(target_arch = "wasm32")))]
Self::Glutin(err) => {
write!(f, "glutin error: {err}")
}
#[cfg(all(feature = "glow", not(target_arch = "wasm32")))]
Self::NoGlutinConfigs(template, err) => {
write!(
f,
"Found no glutin configs matching the template: {template:?}. Error: {err}"
)
}
#[cfg(feature = "glow")]
Self::OpenGL(err) => {
write!(f, "egui_glow: {err}")
}
#[cfg(feature = "wgpu")]
Self::Wgpu(err) => {
write!(f, "WGPU error: {err}")
}
}
}
} }
/// Short for `Result<T, eframe::Error>`. /// Short for `Result<T, eframe::Error>`.

Loading…
Cancel
Save