Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,36 @@ impl<'a> Formatter<'a> {
self.flags & (1 << FlagV1::SignAwareZeroPad as u32) != 0
}

/// Calls the `Debug` implementation of `D` on this `Formatter`.
/// This is equivalent to `{ <D as Debug>::fmt(&d, fmt); drop(d); }`
/// but reads better when you are calling other methods on the `Formatter`.
///
/// # Examples
///
/// ```rust
/// #![feature(formatter_debug)]
/// use std::fmt;
///
/// struct Arm<L, R>(L, R);
///
/// impl<L: fmt::Debug, R: fmt::Debug> fmt::Debug for Arm<L, R> {
/// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
/// write!(fmt, "{:?} => ", self.0)?;
/// fmt.debug(&self.1)
/// }
/// }
///
/// // `fmt.debug(..)` respects formatting on the RHS of the arrow:
/// assert_eq!(format!("{:?}", Arm(0, vec![2, 3])),
/// "0 => [2, 3]");
/// assert_eq!(format!("{:#?}", Arm(0, vec![2, 3])),
/// "0 => [\n 2,\n 3\n]");
/// ```
#[unstable(feature = "formatter_debug", issue = "0")]
pub fn debug<D: Debug>(&mut self, d: D) -> Result {
<D as Debug>::fmt(&d, self)
}

// FIXME: Decide what public API we want for these two flags.
// https://github.com/rust-lang/rust/issues/48584
fn debug_lower_hex(&self) -> bool { self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0 }
Expand Down