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§
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for KeyValue<'a>
impl<'a> !Send for KeyValue<'a>
impl<'a> !Sync for KeyValue<'a>
impl<'a> !UnwindSafe for KeyValue<'a>
impl<'a> Freeze for KeyValue<'a>
impl<'a> Unpin for KeyValue<'a>
impl<'a> UnsafeUnpin for KeyValue<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more