serde_hkx_features/
alt_map.rs
1use crate::ClassMap;
2use crate::error::{KeyParseSnafu, Result};
3use havok_classes::Classes;
4use indexmap::IndexMap;
5use rayon::prelude::*;
6use snafu::ResultExt as _;
7use std::borrow::Cow;
8
9pub type ClassMapAlt<'a> = IndexMap<Cow<'a, str>, Classes<'a>>;
12
13pub fn convert_to_usize_keys(input: ClassMapAlt<'_>) -> Result<ClassMap<'_>> {
18 input
19 .into_par_iter()
20 .map(|(key, value)| {
21 key.parse::<usize>()
22 .map(|parsed_key| (parsed_key, value))
23 .with_context(|_| KeyParseSnafu {
24 key: key.into_owned(),
25 })
26 })
27 .collect()
28}
29
30pub fn convert_to_string_keys(input: ClassMap<'_>) -> ClassMapAlt<'_> {
32 input
33 .into_par_iter()
34 .map(|(key, value)| (Cow::Owned(key.to_string()), value))
35 .collect()
36}