MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / format_map

Function format_map

src/repr/src/strconv.rs:1409–1439  ·  view source on GitHub ↗
(
    buf: &mut F,
    elems: impl IntoIterator<Item = (impl AsRef<str>, T)>,
    mut format_elem: impl FnMut(MapValueWriter<F>, T) -> Result<Nestable, E>,
)

Source from the content-addressed store, hash-verified

1407}
1408
1409pub fn format_map<F, T, E>(
1410 buf: &mut F,
1411 elems: impl IntoIterator<Item = (impl AsRef<str>, T)>,
1412 mut format_elem: impl FnMut(MapValueWriter<F>, T) -> Result<Nestable, E>,
1413) -> Result<Nestable, E>
1414where
1415 F: FormatBuffer,
1416{
1417 buf.write_char('{');
1418 let mut elems = elems.into_iter().peekable();
1419 while let Some((key, value)) = elems.next() {
1420 // Map key values are always Strings, which always evaluate to
1421 // Nestable::MayNeedEscaping.
1422 let key_start = buf.len();
1423 buf.write_str(key.as_ref());
1424 escape_elem::<_, MapElementEscaper>(buf, key_start);
1425
1426 buf.write_str("=>");
1427
1428 let value_start = buf.len();
1429 if let Nestable::MayNeedEscaping = format_elem(MapValueWriter(buf), value)? {
1430 escape_elem::<_, MapElementEscaper>(buf, value_start);
1431 }
1432
1433 if elems.peek().is_some() {
1434 buf.write_char(',');
1435 }
1436 }
1437 buf.write_char('}');
1438 Ok(Nestable::Yes)
1439}
1440
1441pub fn parse_range<'a, V, E>(
1442 s: &'a str,

Callers 2

stringify_datumFunction · 0.85
encode_textMethod · 0.85

Calls 9

MapValueWriterClass · 0.85
write_charMethod · 0.80
is_someMethod · 0.80
into_iterMethod · 0.45
nextMethod · 0.45
lenMethod · 0.45
write_strMethod · 0.45
as_refMethod · 0.45
peekMethod · 0.45

Tested by

no test coverage detected