Skip to content

Commit

Permalink
Remove AsDisplay trait in error formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
scoopr authored and kvark committed Aug 3, 2021
1 parent 019dca3 commit 78e4cd5
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions wgpu-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@ use crate::{
hub::{Global, IdentityManagerFactory},
};

pub trait AsDisplay {
fn as_display(&self) -> &dyn fmt::Display;
}

impl<T: fmt::Display> AsDisplay for T {
fn as_display(&self) -> &dyn fmt::Display {
self
}
}

pub struct ErrorFormatter<'a> {
writer: &'a mut dyn fmt::Write,
global: &'a Global<IdentityManagerFactory>,
}

impl<'a> ErrorFormatter<'a> {
pub fn error(&mut self, err: &dyn fmt::Display) {
pub fn error(&mut self, err: &dyn Error) {
writeln!(self.writer, " {}", err).expect("Error formatting error");
}

Expand Down Expand Up @@ -103,9 +93,9 @@ impl<'a> ErrorFormatter<'a> {
}
}

pub trait PrettyError: Error {
pub trait PrettyError: Error + Sized {
fn fmt_pretty(&self, fmt: &mut ErrorFormatter) {
fmt.error(self.as_display());
fmt.error(self);
}
}

Expand Down Expand Up @@ -154,7 +144,7 @@ pub fn format_pretty_any(
}

// default
fmt.error(error.as_display())
fmt.error(error)
}

#[derive(Debug)]
Expand All @@ -167,7 +157,7 @@ pub struct ContextError {

impl PrettyError for ContextError {
fn fmt_pretty(&self, fmt: &mut ErrorFormatter) {
fmt.error(self.as_display());
fmt.error(self);
fmt.label(self.label_key, &self.label);
}
}
Expand Down

0 comments on commit 78e4cd5

Please sign in to comment.