pub struct KeyValue<'a> { /* private fields */ }Expand description
Display a dynamic list of key-value pairs in a YAML-like style.
Keys are left-aligned and single-line values are aligned into a common column
just past the longest key. A value that renders to multiple lines (for example
a nested KeyValue or any other multi-line block) is placed on the lines
following its key, indented by two spaces. This keeps nested structures visibly
subordinate to their key regardless of whether the value is itself a key-value
list or an opaque block.
§Examples
use diskann_benchmark_runner::utils::fmt::KeyValue;
let mut kv = KeyValue::new();
kv.push("a", &1);
kv.push("hello", &"world");
let expected = "a: 1\nhello: world";
assert_eq!(kv.to_string(), expected);Multi-line values are indented beneath their key:
use diskann_benchmark_runner::utils::fmt::KeyValue;
let mut inner = KeyValue::new();
inner.push("x", &1);
inner.push("yy", &2);
let inner = inner.to_string();
let mut kv = KeyValue::new();
kv.push("name", &"example");
kv.push("nested", &inner);
let expected = "name: example\nnested:\n x: 1\n yy: 2";
assert_eq!(kv.to_string(), expected);Implementations§
Source§impl<'a> KeyValue<'a>
impl<'a> KeyValue<'a>
Sourcepub fn push(&mut self, key: &'a str, value: &'a dyn Display)
pub fn push(&mut self, key: &'a str, value: &'a dyn Display)
Push the key-value pair to self for formatting.
Sourcepub fn push_debug(&mut self, key: &'a str, value: &'a dyn Debug)
pub fn push_debug(&mut self, key: &'a str, value: &'a dyn Debug)
Push the key-value pair to self for formatting via std::fmt::Debug.
Sourcepub fn push_eager<D>(&mut self, key: &'a str, value: D)where
D: Display,
pub fn push_eager<D>(&mut self, key: &'a str, value: D)where
D: Display,
Push the key-value pair to self for formatting - eagerly formatting value.
Sourcepub fn push_eager_nested<D>(&mut self, key: &'a str, value: D)where
D: Display,
pub fn push_eager_nested<D>(&mut self, key: &'a str, value: D)where
D: Display,
Push the key-value pair to self for formatting - eagerly formatting value.