serde_hkx_features/
tree.rs
1use crate::{ClassMap, error::Result, fs::ReadExt};
3use serde_hkx::tree::HavokTree as _;
4use std::path::Path;
5use tokio::fs;
6
7pub async fn write_tree<I, O>(input: I, output: Option<O>) -> Result<()>
13where
14 I: AsRef<Path>,
15 O: AsRef<Path>,
16{
17 let tree = generate(input).await?; match output.as_ref() {
19 Some(output) => fs::write(output, &tree).await?,
20 None => print!("{tree}"),
21 };
22 Ok(())
23}
24
25pub async fn generate<P>(input: P) -> Result<String>
30where
31 P: AsRef<Path>,
32{
33 let bytes = input.read_bytes().await?;
34 let mut string = String::new();
35 let mut class_map: ClassMap = {
36 #[cfg(not(feature = "extra_fmt"))]
37 {
38 crate::serde::de::deserialize(&bytes, &mut string, input)?
39 }
40 #[cfg(feature = "extra_fmt")]
41 {
42 crate::serde_extra::de::deserialize(&bytes, &mut string, input)?
43 }
44 };
45
46 Ok(class_map.tree_for_bytes())
47}