Trait std::fmt::Debug
[−]
[src]
pub trait Debug {
fn fmt(&self, &mut Formatter) -> Result<(), Error>;
}Format trait for the ? character.
Debug should format the output in a programmer-facing, debugging context.
Generally speaking, you should just derive a Debug implementation.
When used with the alternate format specifier #?, the output is pretty-printed.
For more information on formatters, see the module-level documentation.
This trait can be used with #[derive].
Examples
Deriving an implementation:
fn main() { #[derive(Debug)] struct Point { x: i32, y: i32, } let origin = Point { x: 0, y: 0 }; println!("The origin is: {:?}", origin); }#[derive(Debug)] struct Point { x: i32, y: i32, } let origin = Point { x: 0, y: 0 }; println!("The origin is: {:?}", origin);
Manually implementing:
fn main() { use std::fmt; struct Point { x: i32, y: i32, } impl fmt::Debug for Point { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Point {{ x: {}, y: {} }}", self.x, self.y) } } let origin = Point { x: 0, y: 0 }; println!("The origin is: {:?}", origin); }use std::fmt; struct Point { x: i32, y: i32, } impl fmt::Debug for Point { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Point {{ x: {}, y: {} }}", self.x, self.y) } } let origin = Point { x: 0, y: 0 }; println!("The origin is: {:?}", origin);
This outputs:
The origin is: Point { x: 0, y: 0 }
There are a number of debug_* methods on Formatter to help you with manual
implementations, such as debug_struct.
Debug implementations using either derive or the debug builder API
on Formatter support pretty printing using the alternate flag: {:#?}.
Pretty printing with #?:
#[derive(Debug)] struct Point { x: i32, y: i32, } let origin = Point { x: 0, y: 0 }; println!("The origin is: {:#?}", origin);
This outputs:
The origin is: Point {
x: 0,
y: 0
}
Required Methods
Implementors
impl Debug for ()impl<T> Debug for [T] where T: Debugimpl<T11> Debug for (T11,) where T11: Debugimpl<T10, T11> Debug for (T10, T11) where T11: Debug, T10: Debugimpl<T9, T10, T11> Debug for (T9, T10, T11) where T9: Debug, T10: Debug, T11: Debugimpl<T8, T9, T10, T11> Debug for (T8, T9, T10, T11) where T9: Debug, T11: Debug, T8: Debug, T10: Debugimpl<T7, T8, T9, T10, T11> Debug for (T7, T8, T9, T10, T11) where T8: Debug, T9: Debug, T11: Debug, T7: Debug, T10: Debugimpl<T6, T7, T8, T9, T10, T11> Debug for (T6, T7, T8, T9, T10, T11) where T9: Debug, T10: Debug, T6: Debug, T11: Debug, T7: Debug, T8: Debugimpl<T5, T6, T7, T8, T9, T10, T11> Debug for (T5, T6, T7, T8, T9, T10, T11) where T5: Debug, T10: Debug, T9: Debug, T6: Debug, T11: Debug, T8: Debug, T7: Debugimpl<T4, T5, T6, T7, T8, T9, T10, T11> Debug for (T4, T5, T6, T7, T8, T9, T10, T11) where T6: Debug, T11: Debug, T5: Debug, T4: Debug, T8: Debug, T9: Debug, T7: Debug, T10: Debugimpl<T3, T4, T5, T6, T7, T8, T9, T10, T11> Debug for (T3, T4, T5, T6, T7, T8, T9, T10, T11) where T10: Debug, T3: Debug, T11: Debug, T5: Debug, T4: Debug, T6: Debug, T8: Debug, T7: Debug, T9: Debugimpl<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Debug for (T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) where T6: Debug, T3: Debug, T4: Debug, T7: Debug, T8: Debug, T11: Debug, T2: Debug, T10: Debug, T9: Debug, T5: Debugimpl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Debug for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) where T11: Debug, T7: Debug, T5: Debug, T9: Debug, T8: Debug, T2: Debug, T4: Debug, T10: Debug, T1: Debug, T6: Debug, T3: Debugimpl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Debug for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) where T6: Debug, T8: Debug, T7: Debug, T1: Debug, T0: Debug, T4: Debug, T11: Debug, T2: Debug, T5: Debug, T9: Debug, T3: Debug, T10: Debugimpl<T> Debug for *mut Timpl<T> Debug for *const Timpl Debug for f64impl Debug for f32impl Debug for charimpl Debug for strimpl Debug for boolimpl Debug for u64impl Debug for i64impl Debug for u32impl Debug for i32impl Debug for u16impl Debug for i16impl Debug for u8impl Debug for i8impl Debug for usizeimpl Debug for isizeimpl<T> Debug for [T; 32] where T: Debugimpl<T> Debug for [T; 31] where T: Debugimpl<T> Debug for [T; 30] where T: Debugimpl<T> Debug for [T; 29] where T: Debugimpl<T> Debug for [T; 28] where T: Debugimpl<T> Debug for [T; 27] where T: Debugimpl<T> Debug for [T; 26] where T: Debugimpl<T> Debug for [T; 25] where T: Debugimpl<T> Debug for [T; 24] where T: Debugimpl<T> Debug for [T; 23] where T: Debugimpl<T> Debug for [T; 22] where T: Debugimpl<T> Debug for [T; 21] where T: Debugimpl<T> Debug for [T; 20] where T: Debugimpl<T> Debug for [T; 19] where T: Debugimpl<T> Debug for [T; 18] where T: Debugimpl<T> Debug for [T; 17] where T: Debugimpl<T> Debug for [T; 16] where T: Debugimpl<T> Debug for [T; 15] where T: Debugimpl<T> Debug for [T; 14] where T: Debugimpl<T> Debug for [T; 13] where T: Debugimpl<T> Debug for [T; 12] where T: Debugimpl<T> Debug for [T; 11] where T: Debugimpl<T> Debug for [T; 10] where T: Debugimpl<T> Debug for [T; 9] where T: Debugimpl<T> Debug for [T; 8] where T: Debugimpl<T> Debug for [T; 7] where T: Debugimpl<T> Debug for [T; 6] where T: Debugimpl<T> Debug for [T; 5] where T: Debugimpl<T> Debug for [T; 4] where T: Debugimpl<T> Debug for [T; 3] where T: Debugimpl<T> Debug for [T; 2] where T: Debugimpl<T> Debug for [T; 1] where T: Debugimpl<T> Debug for [T; 0] where T: Debugimpl Debug for TypeIdimpl<T> Debug for Cell<T> where T: Copy + Debugimpl<T> Debug for RefCell<T> where T: Debug + ?Sizedimpl Debug for BorrowStateimpl<'b, T> Debug for Ref<'b, T> where T: Debug + ?Sizedimpl<'b, T> Debug for RefMut<'b, T> where T: Debug + ?Sizedimpl<T> Debug for UnsafeCell<T> where T: Debug + ?Sizedimpl Debug for Orderingimpl<H> Debug for BuildHasherDefault<H>impl Debug for SipHasherimpl<T> Debug for Rev<T> where T: Debugimpl<I> Debug for Cloned<I> where I: Debugimpl<I> Debug for Cycle<I> where I: Debugimpl<A, B> Debug for Chain<A, B> where A: Debug, B: Debugimpl<A, B> Debug for Zip<A, B> where B: Debug, A: Debugimpl<I, F> Debug for Map<I, F> where I: Debugimpl<I, P> Debug for Filter<I, P> where I: Debugimpl<I, F> Debug for FilterMap<I, F> where I: Debugimpl<I> Debug for Enumerate<I> where I: Debugimpl<I> Debug for Peekable<I> where I: Iterator + Debug, I::Item: Debugimpl<I, P> Debug for SkipWhile<I, P> where I: Debugimpl<I, P> Debug for TakeWhile<I, P> where I: Debugimpl<I> Debug for Skip<I> where I: Debugimpl<I> Debug for Take<I> where I: Debugimpl<I, St, F> Debug for Scan<I, St, F> where St: Debug, I: Debugimpl<I, U, F> Debug for FlatMap<I, U, F> where U: IntoIterator, I: Debug, U::IntoIter: Debugimpl<I> Debug for Fuse<I> where I: Debugimpl<I, F> Debug for Inspect<I, F> where I: Debugimpl<A, R> Debug for StepBy<A, R> where R: Debug, A: Debugimpl<A> Debug for Repeat<A> where A: Debugimpl<T> Debug for Empty<T>impl<T> Debug for Once<T> where T: Debugimpl<T> Debug for PhantomData<T> where T: ?Sizedimpl Debug for RangeFullimpl<Idx> Debug for Range<Idx> where Idx: Debugimpl<Idx> Debug for RangeFrom<Idx> where Idx: Debugimpl<Idx> Debug for RangeTo<Idx> where Idx: Debugimpl<Idx> Debug for RangeInclusive<Idx> where Idx: Debugimpl<Idx> Debug for RangeToInclusive<Idx> where Idx: Debugimpl<T, E> Debug for Result<T, E> where T: Debug, E: Debugimpl<'a, T> Debug for Iter<'a, T> where T: 'a + Debugimpl<'a, T> Debug for IterMut<'a, T> where T: 'a + Debugimpl<T> Debug for IntoIter<T> where T: Debugimpl<T> Debug for Option<T> where T: Debugimpl<'a, A> Debug for Iter<'a, A> where A: 'a + Debugimpl<'a, A> Debug for IterMut<'a, A> where A: 'a + Debugimpl<A> Debug for IntoIter<A> where A: Debugimpl<T> Debug for Box<T> where T: Debug + ?Sizedimpl<T> Debug for Rc<T> where T: Debug + ?Sizedimpl<T> Debug for Weak<T> where T: Debug + ?Sizedimpl<'a, B> Debug for Cow<'a, B> where B: Debug + ToOwned + ?Sized, B::Owned: Debugimpl Debug for Errorimpl<'a> Debug for Arguments<'a>impl<'a, T, P> Debug for Split<'a, T, P> where P: FnMut(&T) -> bool, T: 'a + Debugimpl<'a, T, P> Debug for SplitN<'a, T, P> where P: FnMut(&T) -> bool, T: 'a + Debugimpl<'a, T> Debug for Iter<'a, T> where T: 'a + Debugimpl<'a, T, P> Debug for RSplitNMut<'a, T, P> where T: 'a + Debug, P: FnMut(&T) -> boolimpl<'a, T> Debug for Chunks<'a, T> where T: 'a + Debugimpl<'a, T> Debug for IterMut<'a, T> where T: 'a + Debugimpl<'a, T, P> Debug for RSplitN<'a, T, P> where P: FnMut(&T) -> bool, T: 'a + Debugimpl<'a, T, P> Debug for SplitNMut<'a, T, P> where P: FnMut(&T) -> bool, T: 'a + Debugimpl<'a, T> Debug for Windows<'a, T> where T: 'a + Debugimpl<'a, T, P> Debug for SplitMut<'a, T, P> where P: FnMut(&T) -> bool, T: 'a + Debugimpl<'a, T> Debug for ChunksMut<'a, T> where T: 'a + Debugimpl Debug for CharRangeimpl<'a, P> Debug for MatchIndices<'a, P> where P: Pattern<'a>, P::Searcher: Debugimpl<'a, P> Debug for RSplitTerminator<'a, P> where P: Pattern<'a>, P::Searcher: Debugimpl<'a> Debug for CharIndices<'a>impl<'a, P> Debug for Split<'a, P> where P: Pattern<'a>, P::Searcher: Debugimpl<'a> Debug for LinesAny<'a>impl<'a> Debug for Lines<'a>impl<'a> Debug for Chars<'a>impl<'a, P> Debug for RMatches<'a, P> where P: Pattern<'a>, P::Searcher: Debugimpl<'a, P> Debug for RSplitN<'a, P> where P: Pattern<'a>, P::Searcher: Debugimpl Debug for SearchStepimpl<'a> Debug for CharSearcher<'a>impl<'a, 'b> Debug for CharSliceSearcher<'a, 'b>impl<'a, F> Debug for CharPredicateSearcher<'a, F> where F: FnMut(char) -> boolimpl<'a, 'b> Debug for StrSearcher<'a, 'b>impl<'a, P> Debug for SplitN<'a, P> where P: Pattern<'a>, P::Searcher: Debugimpl<'a> Debug for Bytes<'a>impl<'a, P> Debug for Matches<'a, P> where P: Pattern<'a>, P::Searcher: Debugimpl<'a, P> Debug for RSplit<'a, P> where P: Pattern<'a>, P::Searcher: Debugimpl Debug for ParseBoolErrorimpl<'a, P> Debug for SplitTerminator<'a, P> where P: Pattern<'a>, P::Searcher: Debugimpl<'a, P> Debug for RMatchIndices<'a, P> where P: Pattern<'a>, P::Searcher: Debugimpl Debug for Utf8Errorimpl Debug for Stringimpl Debug for FromUtf8Errorimpl Debug for FromUtf16Errorimpl Debug for ParseErrorimpl<T> Debug for Vec<T> where T: Debugimpl Debug for DecodeUtf16Errorimpl Debug for EncodeUtf8impl Debug for EncodeUtf16impl Debug for EscapeUnicodeimpl Debug for EscapeDefaultimpl Debug for FpCategoryimpl Debug for ParseIntErrorimpl<T> Debug for Wrapping<T> where T: Debugimpl Debug for Threadimpl<T> Debug for Bound<T> where T: Debugimpl<T> Debug for BinaryHeap<T> where T: Ord + Debugimpl<K, V> Debug for BTreeMap<K, V> where V: Debug, K: Debugimpl<T> Debug for BTreeSet<T> where T: Debugimpl<A> Debug for LinkedList<A> where A: Debugimpl<T> Debug for VecDeque<T> where T: Debugimpl<K, V, S> Debug for HashMap<K, V, S> where K: Eq + Hash + Debug, V: Debug, S: BuildHasherimpl<T, S> Debug for HashSet<T, S> where T: Eq + Hash + Debug, S: BuildHasherimpl Debug for VarErrorimpl Debug for JoinPathsErrorimpl Debug for NulErrorimpl Debug for IntoStringErrorimpl Debug for CStringimpl Debug for CStrimpl Debug for OsStringimpl Debug for OsStrimpl Debug for Permissionsimpl Debug for Fileimpl<R> Debug for BufReader<R> where R: Debugimpl<W: Debug> Debug for IntoInnerError<W>impl<W: Write> Debug for BufWriter<W> where W: Debugimpl<W: Write> Debug for LineWriter<W> where W: Debugimpl<T: Debug> Debug for Cursor<T>impl Debug for Errorimpl Debug for ErrorKindimpl Debug for SeekFromimpl Debug for CharsErrorimpl Debug for IpAddrimpl Debug for Ipv6MulticastScopeimpl Debug for Ipv4Addrimpl Debug for Ipv6Addrimpl Debug for SocketAddrimpl Debug for SocketAddrV4impl Debug for SocketAddrV6impl Debug for TcpStreamimpl Debug for TcpListenerimpl Debug for UdpSocketimpl Debug for AddrParseErrorimpl Debug for Shutdownimpl Debug for SocketAddrimpl Debug for UnixStreamimpl Debug for UnixListenerimpl<'a> Debug for Incoming<'a>impl Debug for UnixDatagramimpl<'a> Debug for Prefix<'a>impl<'a> Debug for PrefixComponent<'a>impl<'a> Debug for Component<'a>impl Debug for PathBufimpl Debug for StripPrefixErrorimpl Debug for Pathimpl<'a> Debug for Display<'a>impl Debug for Commandimpl Debug for Outputimpl Debug for ExitStatusimpl<T> Debug for Arc<T> where T: Debug + ?Sizedimpl<T> Debug for Weak<T> where T: Debug + ?Sizedimpl Debug for AtomicBoolimpl Debug for AtomicIsizeimpl Debug for AtomicUsizeimpl<T> Debug for AtomicPtr<T>impl Debug for Orderingimpl Debug for Selectimpl<'rx, T: Send + 'rx> Debug for Handle<'rx, T>impl Debug for RecvErrorimpl Debug for TryRecvErrorimpl<T> Debug for Sender<T>impl<T> Debug for SyncSender<T>impl<T> Debug for Receiver<T>impl<T> Debug for SendError<T>impl<T> Debug for TrySendError<T>impl Debug for WaitTimeoutResultimpl<T: ?Sized + Debug> Debug for Mutex<T>impl<T: ?Sized + Debug> Debug for RwLock<T>impl Debug for Durationimpl Debug for SystemTimeErrorimpl Debug for Instantimpl Debug for SystemTimeimpl<T> Debug for PoisonError<T>impl<T> Debug for TryLockError<T>impl Debug for SocketAddrimpl Debug for UnixStreamimpl Debug for UnixListenerimpl<'a> Debug for Incoming<'a>impl Debug for UnixDatagram