use core::fmt::{Alignment, Arguments, Formatter, Result, Write};
mod sealed { pubtrait Sealed {}
impl Sealed for core::fmt::Formatter<'_> {}
}
/// An extension trait for [`core::fmt::Formatter`]. pubtrait FormatterExt: sealed::Sealed { /// Writes the given arguments to the formatter, padding them with the given width. If `width` /// is incorrect, the resulting output will not be the requested width. fn pad_with_width(&mutself, width: usize, args: Arguments<'_>) -> Result;
}
impl FormatterExt for Formatter<'_> { fn pad_with_width(&mutself, args_width: usize, args: Arguments<'_>) -> Result { let Some(final_width) = self.width() else { // The caller has not requested a width. Write the arguments as-is. returnself.write_fmt(args);
}; let Some(fill_width @ 1..) = final_width.checked_sub(args_width) else { // No padding will be present. Write the arguments as-is. returnself.write_fmt(args);
};
let alignment = self.align().unwrap_or(Alignment::Left); let fill = self.fill();
let left_fill_width = match alignment {
Alignment::Left => 0,
Alignment::Right => fill_width,
Alignment::Center => fill_width / 2,
}; let right_fill_width = match alignment {
Alignment::Left => fill_width,
Alignment::Right => 0, // When the fill is not even on both sides, the extra fill goes on the right.
Alignment::Center => (fill_width + 1) / 2,
};
for _ in0..left_fill_width { self.write_char(fill)?;
} self.write_fmt(args)?; for _ in0..right_fill_width { self.write_char(fill)?;
}
Ok(())
}
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.9Bemerkung:
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.