concord 2.4.3

A terminal user interface client for Discord
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use std::collections::BTreeMap;

use serde_json::Value;

/// Collects the fields of a JSON object that are not in `known_fields`.
/// Parsers stash these so unrecognized Discord payload fields survive a
/// parse/serialize round trip instead of being dropped.
pub(crate) fn extra_fields(value: &Value, known_fields: &[&str]) -> BTreeMap<String, Value> {
    let Some(object) = value.as_object() else {
        return BTreeMap::new();
    };
    object
        .iter()
        .filter(|(field, _)| !known_fields.contains(&field.as_str()))
        .map(|(field, value)| (field.clone(), value.clone()))
        .collect()
}