| 1 |
#![cfg_attr(docsrs, doc(cfg(feature = "sval")))] |
| 2 |
|
| 3 |
use crate::{IndexMap, IndexSet}; |
| 4 |
use sval::{Stream, Value}; |
| 5 |
|
| 6 |
impl<K: Value, V: Value, S> Value for IndexMap<K, V, S> { |
| 7 |
fn stream<'sval, ST: Stream<'sval> + ?Sized>(&'sval self, stream: &mut ST) -> sval::Result { |
| 8 |
stream.map_begin(Some(self.len()))?; |
| 9 |
|
| 10 |
for (k, v) in self { |
| 11 |
stream.map_key_begin()?; |
| 12 |
stream.value(k)?; |
| 13 |
stream.map_key_end()?; |
| 14 |
|
| 15 |
stream.map_value_begin()?; |
| 16 |
stream.value(v)?; |
| 17 |
stream.map_value_end()?; |
| 18 |
} |
| 19 |
|
| 20 |
stream.map_end() |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
impl<K: Value, S> Value for IndexSet<K, S> { |
| 25 |
fn stream<'sval, ST: Stream<'sval> + ?Sized>(&'sval self, stream: &mut ST) -> sval::Result { |
| 26 |
stream.seq_begin(Some(self.len()))?; |
| 27 |
|
| 28 |
for value in self { |
| 29 |
stream.seq_value_begin()?; |
| 30 |
stream.value(value)?; |
| 31 |
stream.seq_value_end()?; |
| 32 |
} |
| 33 |
|
| 34 |
stream.seq_end() |
| 35 |
} |
| 36 |
} |