fn pack_dict<'a, 'scratch>(
    row: &mut Row,
    mut scratch: VecStack<'scratch, DictEntry<'a>>,
    mut entries: &'a [Command<'a>],
) {
    while !entries.is_empty() {
        if let Command::String(key) = &entries[0] {
            entries = &entries[1..];
            let val = extract_value(&mut entries);
            scratch.push(DictEntry { key, val });
        } else {
            unreachable!("JSON decoding produced invalid command sequence");
        }
    }

    // Keys must be written in ascending order, per the requirements of our
    // `Row` representation. If keys are duplicated, we must keep only the last
    // value for the key, as ordered by appearance in the source JSON, per
    // PostgreSQL's implementation.
    scratch.sort_by_key(|entry| entry.key);
    row.push_dict_with(|row| {
        for i in 0..scratch.len() {
            if i == scratch.len() - 1 || scratch[i].key != scratch[i + 1].key {
                let DictEntry { key, val } = scratch[i];
                row.push(Datum::String(key));
                pack_value(row, scratch.fresh(), val);
            }
        }
    });
}
/// Packs a sequence of (key, val) pairs as an ordered dictionary.
///
/// The keys are required to be `Command::String` variants, and
/// the entries in the dictionary are sorted by these strings.
/// Multiple values for the same key are detected and only
/// the last value is kept.
Packs a sequence of (key, val) pairs as an ordered dictionary.
The keys are required to be `Command::String` variants, and
the entries in the dictionary are sorted by these strings.
Multiple values for the same key are detected and only
the last value is kept.
Packs a sequence of ( key val ) pairs as an ordered dictionary . The keys are required to be ` Command :: String ` variants and the entries in the dictionary are sorted by these strings . Multiple values for the same key are detected and only the last value is kept .
fn pack_dict<'a, 'scratch>(
    row: &mut Row,
    mut scratch: VecStack<'scratch, DictEntry<'a>>,
    mut entries: &'a [Command<'a>],
) {
    while !entries.is_empty() {
        if let Command::String(key) = &entries[0] {
            entries = &entries[1..];
            let val = extract_value(&mut entries);
            scratch.push(DictEntry { key, val });
        } else {
            unreachable!("JSON decoding produced invalid command sequence");
        }
    }
    // Keys must be written in ascending order, per the requirements of our
    // `Row` representation. If keys are duplicated, we must keep only the last
    // value for the key, as ordered by appearance in the source JSON, per
    // PostgreSQL's implementation.
    scratch.sort_by_key(|entry| entry.key);
    row.push_dict_with(|row| {
        for i in 0..scratch.len() {
            if i == scratch.len() - 1 || scratch[i].key != scratch[i + 1].key {
                let DictEntry { key, val } = scratch[i];
                row.push(Datum::String(key));
                pack_value(row, scratch.fresh(), val);
            }
        }
    });
}
fn pack_dict < ' a , ' scratch > ( row : & mut Row , mut scratch : VecStack < ' scratch , DictEntry < ' a > > , mut entries : & ' a [ Command < ' a > ] , ) { while ! entries . is_empty ( ) { if let Command :: String ( key ) = & entries [ 0 ] { entries = & entries [ 1 .. ] ; let val = extract_value ( & mut entries ) ; scratch . push ( DictEntry { key , val } ) ; } else { unreachable ! ( " " ) ; } } // Keys must be written in ascending order, per the requirements of our // `Row` representation. If keys are duplicated, we must keep only the last // value for the key, as ordered by appearance in the source JSON, per // PostgreSQL's implementation. scratch . sort_by_key ( | entry | entry . key ) ; row . push_dict_with ( | row | { for i in 0 .. scratch . len ( ) { if i == scratch . len ( ) - 1 || scratch [ i ] . key != scratch [ i + 1 ] . key { let DictEntry { key , val } = scratch [ i ] ; row . push ( Datum :: String ( key ) ) ; pack_value ( row , scratch . fresh ( ) , val ) ; } } } ) ; }
Packs a sequence of (key, val) pairs as an ordered dictionary.
Packs a sequence of ( key val ) pairs as an ordered dictionary .
row
&mut Row
scratch
VecStack<'scratch, DictEntry<'a>>
entries
&'a [Command<'a>]
row
&mut Row
scratch
VecStack<'scratch, DictEntry<'a>>
entries
&'a [Command<'a>]