use indexmap::IndexMap;
#[cfg(feature = "serialization")]
use serde::{Deserialize, Serialize};
pub mod parser;
pub(crate) mod utils;
pub mod vmf;
pub mod errors;
pub mod prelude;
pub use errors::{VmfError, VmfResult};
pub trait VmfSerializable {
fn to_vmf_string(&self, indent_level: usize) -> String;
}
pub mod vmf_file;
pub use vmf_file::VmfFile;
#[derive(Debug, Default)]
pub struct VmfBlock {
pub name: String,
pub key_values: IndexMap<String, String>, pub blocks: Vec<VmfBlock>,
}
impl VmfBlock {
pub fn serialize(&self, indent_level: usize) -> String {
let indent = "\t".repeat(indent_level);
let mut output = String::new();
output.push_str(&format!("{}{}\n", indent, self.name));
output.push_str(&format!("{}{{\n", indent));
for (key, value) in &self.key_values {
output.push_str(&format!("{}\t\"{}\" \"{}\"\n", indent, key, value));
}
for block in &self.blocks {
output.push_str(&block.serialize(indent_level + 1));
}
output.push_str(&format!("{}}}\n", indent));
output
}
}