mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Remove AsDisplay trait in error formatting
This commit is contained in:
committed by
Dzmitry Malyshau
parent
019dca3cfa
commit
78e4cd5dbc
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +144,7 @@ pub fn format_pretty_any(
|
||||
}
|
||||
|
||||
// default
|
||||
fmt.error(error.as_display())
|
||||
fmt.error(error)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user