Trait core::fmt::Debug
[−]
[src]
pub trait Debug {
fn fmt(&self, &mut Formatter) -> Result;
}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.
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, "({}, {})", 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, "({}, {})", 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<T: Debug> Debug for Wrapping<T>impl Debug for FpCategoryimpl Debug for ParseIntErrorimpl Debug for ParseFloatErrorimpl<T: Debug + Zeroable> Debug for NonZero<T>impl Debug for RangeFullimpl<Idx: Debug> Debug for Range<Idx>impl<Idx: Debug> Debug for RangeFrom<Idx>impl<Idx: Debug> Debug for RangeTo<Idx>impl Debug for Orderingimpl Debug for Anyimpl Debug for Any + Sendimpl Debug for TypeIdimpl<T: Debug> Debug for [T; 0]impl<T: Debug> Debug for [T; 1]impl<T: Debug> Debug for [T; 2]impl<T: Debug> Debug for [T; 3]impl<T: Debug> Debug for [T; 4]impl<T: Debug> Debug for [T; 5]impl<T: Debug> Debug for [T; 6]impl<T: Debug> Debug for [T; 7]impl<T: Debug> Debug for [T; 8]impl<T: Debug> Debug for [T; 9]impl<T: Debug> Debug for [T; 10]impl<T: Debug> Debug for [T; 11]impl<T: Debug> Debug for [T; 12]impl<T: Debug> Debug for [T; 13]impl<T: Debug> Debug for [T; 14]impl<T: Debug> Debug for [T; 15]impl<T: Debug> Debug for [T; 16]impl<T: Debug> Debug for [T; 17]impl<T: Debug> Debug for [T; 18]impl<T: Debug> Debug for [T; 19]impl<T: Debug> Debug for [T; 20]impl<T: Debug> Debug for [T; 21]impl<T: Debug> Debug for [T; 22]impl<T: Debug> Debug for [T; 23]impl<T: Debug> Debug for [T; 24]impl<T: Debug> Debug for [T; 25]impl<T: Debug> Debug for [T; 26]impl<T: Debug> Debug for [T; 27]impl<T: Debug> Debug for [T; 28]impl<T: Debug> Debug for [T; 29]impl<T: Debug> Debug for [T; 30]impl<T: Debug> Debug for [T; 31]impl<T: Debug> Debug for [T; 32]impl Debug for AtomicUsizeimpl Debug for AtomicIsizeimpl Debug for AtomicBoolimpl<T> Debug for AtomicPtr<T>impl Debug for BorrowStateimpl<T: Debug> Debug for Option<T>impl<T: Debug, E: Debug> Debug for Result<T, E>impl Debug for i8x16impl Debug for i16x8impl Debug for i32x4impl Debug for i64x2impl Debug for u8x16impl Debug for u16x8impl Debug for u32x4impl Debug for u64x2impl Debug for f32x4impl Debug for f64x2impl Debug for SearchStepimpl<'a, 'b> Debug for StrSearcher<'a, 'b>impl Debug for ParseBoolErrorimpl Debug for Utf8Errorimpl Debug for RadixFmt<isize, Radix>impl Debug for isizeimpl Debug for RadixFmt<usize, Radix>impl Debug for usizeimpl Debug for RadixFmt<i8, Radix>impl Debug for i8impl Debug for RadixFmt<u8, Radix>impl Debug for u8impl Debug for RadixFmt<i16, Radix>impl Debug for i16impl Debug for RadixFmt<u16, Radix>impl Debug for u16impl Debug for RadixFmt<i32, Radix>impl Debug for i32impl Debug for RadixFmt<u32, Radix>impl Debug for u32impl Debug for RadixFmt<i64, Radix>impl Debug for i64impl Debug for RadixFmt<u64, Radix>impl Debug for u64impl Debug for Errorimpl<'a> Debug for Arguments<'a>impl<'a, T: ?Sized + Debug> Debug for &'a Timpl<'a, T: ?Sized + Debug> Debug for &'a mut Timpl Debug for boolimpl Debug for strimpl Debug for charimpl Debug for f32impl Debug for f64impl<T> Debug for *const Timpl<T> Debug for *mut Timpl<T0: Debug, T1: Debug, T2: Debug, T3: Debug, T4: Debug, T5: Debug, T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11: Debug> Debug for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)impl<T1: Debug, T2: Debug, T3: Debug, T4: Debug, T5: Debug, T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11: Debug> Debug for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)impl<T2: Debug, T3: Debug, T4: Debug, T5: Debug, T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11: Debug> Debug for (T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)impl<T3: Debug, T4: Debug, T5: Debug, T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11: Debug> Debug for (T3, T4, T5, T6, T7, T8, T9, T10, T11)impl<T4: Debug, T5: Debug, T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11: Debug> Debug for (T4, T5, T6, T7, T8, T9, T10, T11)impl<T5: Debug, T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11: Debug> Debug for (T5, T6, T7, T8, T9, T10, T11)impl<T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11: Debug> Debug for (T6, T7, T8, T9, T10, T11)impl<T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11: Debug> Debug for (T7, T8, T9, T10, T11)impl<T8: Debug, T9: Debug, T10: Debug, T11: Debug> Debug for (T8, T9, T10, T11)impl<T9: Debug, T10: Debug, T11: Debug> Debug for (T9, T10, T11)impl<T10: Debug, T11: Debug> Debug for (T10, T11)impl<T11: Debug> Debug for (T11,)impl<T: Debug> Debug for [T]impl Debug for ()impl<T> Debug for PhantomData<T>impl<T: Copy + Debug> Debug for Cell<T>impl<T: ?Sized + Debug> Debug for RefCell<T>impl<'b, T: ?Sized + Debug> Debug for Ref<'b, T>impl<'b, T: ?Sized + Debug> Debug for RefMut<'b, T>