csr version imported
This commit is contained in:
1 parent
2a1fb81567
commit
b09dcb5fc1
19 files changed
+122928
-5
No files matched your search
@@ -0,0 +1,21 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
|
||||
pub fn read_items (contents: &str, map: &mut HashMap<String, Item>) -> usize {
|
||||
let Ok(json): std::result::Result<Value, _> = serde_json::from_str(&contents) else { error!("Can't read Value from contents"); return 0 };
|
||||
let Value::Array(list) = json else { error!("Value isn't Array, skipping"); return 0 };
|
||||
|
||||
let start = map.len();
|
||||
|
||||
for t in list.into_iter().map(Item::from_json).flatten() {
|
||||
if map.contains_key(&t.name) {
|
||||
let entry = map.get_mut(&t.name).unwrap();
|
||||
entry.weight = entry.weight.or(t.weight);
|
||||
entry.rest.extend(t.rest);
|
||||
} else {
|
||||
map.insert(t.name.clone(), t);
|
||||
}
|
||||
}
|
||||
|
||||
map.len() - start
|
||||
}
|
||||
Reference in new issue
Block a user