Skip to main content

DebugExt

Trait DebugExt 

Source
pub trait DebugExt {
    type Ctx;

    // Required method
    fn fmt_with(&self, f: &mut Formatter<'_>, ctx: &Self::Ctx) -> FmtResult<()>;

    // Provided method
    fn debug_with<'a>(&'a self, ctx: &'a Self::Ctx) -> DebugWith<'a, Self>
       where Self: Sized { ... }
}
Expand description

๐Ÿ–น ๐Ÿ› Extension for contextual debugging.


๐Ÿ“ text/fmt


Types implementing this trait support formatting with a caller-supplied context. The context is defined per-type via the Ctx associated type, allowing each type to expose whatever formatting modes it needs without affecting other types.

ยงExamples

enum Mode { Hex, Dec }
struct Value(u32);
impl DebugExt for Value {
    type Ctx = Mode;
    fn fmt_with(&self, f: &mut Formatter, mode: &Self::Ctx) -> FmtResult<()> {
        match mode {
            Mode::Hex => write!(f, "0x{:X}", self.0),
            Mode::Dec => write!(f, "{}", self.0),
        }
    }
}
let v = Value(255);
// caller chooses representation:
// v.fmt_with(f, &Mode::Hex) โ†’ "0xFF"
// v.fmt_with(f, &Mode::Dec) โ†’ "255"

Required Associated Typesยง

Source

type Ctx

The context used to guide formatting.

Required Methodsยง

Source

fn fmt_with(&self, f: &mut Formatter<'_>, ctx: &Self::Ctx) -> FmtResult<()>

Formats self under the given context.

Provided Methodsยง

Source

fn debug_with<'a>(&'a self, ctx: &'a Self::Ctx) -> DebugWith<'a, Self>
where Self: Sized,

Wraps self for contextual debug formatting.

Dyn Compatibilityยง

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementorsยง

Sourceยง

impl DebugExt for AppControlSet

Sourceยง

impl DebugExt for AsciiSet
where AsciiSet: Debug,

Sourceยง

impl DebugExt for BitfieldExample

Available on crate features _docs_examples only.
Sourceยง

impl DebugExt for EnumSetExample

Available on doc or test only.
Sourceยง

impl DebugExt for EventButtons

Available on crate feature event only.
Sourceยง

impl DebugExt for EventTagSet

Available on crate feature event only.
Sourceยง

impl DebugExt for EventTimestamp

Available on crate feature event only.
Sourceยง

impl DebugExt for KeyMods
where KeyMods: Debug,

Available on crate feature event only.
Sourceยง

impl DebugExt for LinuxSigactionFlags

Available on crate feature linux only.
Sourceยง

impl DebugExt for LinuxSignalSet

Available on crate feature linux only.
Sourceยง

impl DebugExt for LinuxTermiosControlFlags

Available on crate feature linux only.
Sourceยง

impl DebugExt for LinuxTermiosInputFlags

Available on crate feature linux only.
Sourceยง

impl DebugExt for LinuxTermiosLocalFlags

Available on crate feature linux only.
Sourceยง

impl DebugExt for LinuxTermiosOutputFlags

Available on crate feature linux only.
Sourceยง

impl DebugExt for RandQualities

Sourceยง

impl DebugExt for RunCapInput

Sourceยง

impl DebugExt for RunCapSystem

Sourceยง

impl DebugExt for RunCapText

Sourceยง

impl DebugExt for TermCaps
where TermCaps: Debug,

Available on crate feature term only.
Sourceยง

impl DebugExt for TermColor

Available on crate feature term only.
Sourceยง

impl DebugExt for TermMode
where TermMode: Debug,

Available on crate feature term only.
Sourceยง

impl DebugExt for TermStyle

Available on crate feature term only.
Sourceยง

impl DebugExt for TermStyleExt

Available on crate feature term only.
Sourceยง

impl DebugExt for TermelMeta

Available on crate feature term only.