pub trait DebugPls {
// Required method
fn fmt(&self, f: Formatter<'_>);
}Expand description
Syntax aware pretty-printed debug formatting.
DebugPls should format the output in a programmer-facing, debugging context.
Generally speaking, you should just derive a Debug implementation.
§Examples
Deriving an implementation:
use dbg_pls::{pretty, DebugPls};
#[derive(DebugPls)]
struct Point {
x: i32,
y: i32,
}
let origin = Point { x: 0, y: 0 };
assert_eq!(format!("The origin is: {}", pretty(&origin)), "The origin is: Point { x: 0, y: 0 }");Manually implementing:
use dbg_pls::{pretty, DebugPls, Formatter};
struct Point {
x: i32,
y: i32,
}
impl DebugPls for Point {
fn fmt(&self, f: Formatter<'_>) {
f.debug_struct("Point")
.field("x", &self.x)
.field("y", &self.y)
.finish()
}
}
let origin = Point { x: 0, y: 0 };
assert_eq!(format!("The origin is: {}", pretty(&origin)), "The origin is: Point { x: 0, y: 0 }");Required Methods§
Sourcefn fmt(&self, f: Formatter<'_>)
fn fmt(&self, f: Formatter<'_>)
Formats the value using the given formatter.
§Examples
use dbg_pls::{pretty, DebugPls, Formatter};
struct Position {
longitude: f32,
latitude: f32,
}
impl DebugPls for Position {
fn fmt(&self, f: Formatter<'_>) {
f.debug_tuple()
.field(&self.longitude)
.field(&self.latitude)
.finish()
}
}
let position = Position { longitude: 1.987, latitude: 2.983 };
assert_eq!(format!("{}", pretty(&position)), "(1.987, 2.983)");