generic_relation_helpers 0.2.0

Traits et helpers génériques pour jointures parent/enfant
Documentation
use std::collections::HashMap;

use serde_json::Value;

use crate::traits::trait_communs::HasFields;

pub fn build_hashmap_from_fields<T: HasFields>(
    source:      &T,
    enfants_key: &str,
    enfants:     Value,
) -> HashMap<String, Value> {
    let mut map: HashMap<String, Value> = T::field_names()
        .iter()
        .map(|&name| (name.to_string(), source.get_fields(name)))
        .collect();

    map.insert(enfants_key.to_string(), enfants);
    map
}