Skip to content
Myr

Merge pull request #52 from dtolnay/quoted

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Remove std dependency from context's Debug impl

authored by David Tolnay · committed by GitHub · parents 4f123ae, 2e711d6 · Browse files · 1 file+22 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+22 added−2 removed

  • other:+22 added−2 removed

1 file+22 added−2 removed

modified:src/context.rs+22 added-2 removed
1use crate::error::ContextError;2use crate::{Context, Error};3use std::convert::Infallible;4use std::error::Error as StdError;5use std::fmt::{self, Debug, Display};5use std::fmt::{self, Debug, Display, Write};67#[cfg(backtrace)]8use std::backtrace::Backtrace;9
92 unmodified lines
102 E: Debug,103{104 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {105 f.debug_struct("Error")106 .field("context", &self.context.to_string())106 .field("context", &Quoted(&self.context))107 .field("source", &self.error)108 .finish()109 }110}
35 unmodified lines
146 Some(&*self.error)147 }148}149150struct Quoted<C>(C);151152impl<C> Debug for Quoted<C>153where154 C: Display,155{156 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {157 formatter.write_char('"')?;158 Quoted(&mut *formatter).write_fmt(format_args!("{}", self.0))?;159 formatter.write_char('"')?;160 Ok(())161 }162}163164impl Write for Quoted<&mut fmt::Formatter<'_>> {165 fn write_str(&mut self, s: &str) -> fmt::Result {166 Display::fmt(&s.escape_debug(), self.0)167 }168}169170pub(crate) mod private {171 use super::*;172173 pub trait Sealed {}
4 unmodified lines