Mercurial > hg
diff rust/hg-core/src/config/config.rs @ 46499:eace48b4a786
rust: Use the DisplayBytes trait in config printing
This is similar to `std::fmt::Display`, but for arbitrary bytes instead
of Unicode. Writing to an abstract output stream helps avoid allocating
intermediate `Vec<u8>` buffers.
Differential Revision: https://phab.mercurial-scm.org/D9966
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Mon, 08 Feb 2021 11:13:56 +0100 |
parents | d7685105e504 |
children | 2e5dd18d6dc3 |
line wrap: on
line diff
--- a/rust/hg-core/src/config/config.rs Thu Feb 04 13:32:11 2021 -0800 +++ b/rust/hg-core/src/config/config.rs Mon Feb 08 11:13:56 2021 +0100 @@ -12,6 +12,7 @@ ConfigError, ConfigLayer, ConfigParseError, ConfigValue, }; use crate::utils::files::get_bytes_from_path; +use format_bytes::{write_bytes, DisplayBytes}; use std::env; use std::path::{Path, PathBuf}; @@ -23,13 +24,22 @@ layers: Vec<layer::ConfigLayer>, } -impl std::fmt::Debug for Config { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl DisplayBytes for Config { + fn display_bytes( + &self, + out: &mut dyn std::io::Write, + ) -> std::io::Result<()> { for (index, layer) in self.layers.iter().rev().enumerate() { - write!( - f, - "==== Layer {} (trusted: {}) ====\n{:?}", - index, layer.trusted, layer + write_bytes!( + out, + b"==== Layer {} (trusted: {}) ====\n{}", + index, + if layer.trusted { + &b"yes"[..] + } else { + &b"no"[..] + }, + layer )?; } Ok(())