mirror of
https://github.com/a2x/cs2-dumper.git
synced 2026-04-18 05:19:58 +08:00
Add YAML file builder and automatically resolve offsets in tests
This commit is contained in:
48
src/builder/yaml_file_builder.rs
Normal file
48
src/builder/yaml_file_builder.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use super::FileBuilder;
|
||||
|
||||
use std::io::{Result, Write};
|
||||
|
||||
/// A structure representing a builder for Yaml files.
|
||||
/// The builder implements the `FileBuilder` trait.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct YamlFileBuilder;
|
||||
|
||||
impl FileBuilder for YamlFileBuilder {
|
||||
fn extension(&mut self) -> &str {
|
||||
"yaml"
|
||||
}
|
||||
|
||||
fn write_top_level(&mut self, output: &mut dyn Write) -> Result<()> {
|
||||
write!(output, "---\n")
|
||||
}
|
||||
|
||||
fn write_namespace(
|
||||
&mut self,
|
||||
output: &mut dyn Write,
|
||||
name: &str,
|
||||
comment: Option<&str>,
|
||||
) -> Result<()> {
|
||||
let comment = comment.map_or(String::new(), |c| format!(" # {}", c));
|
||||
|
||||
write!(output, "{}:{}\n", name, comment)
|
||||
}
|
||||
|
||||
fn write_variable(
|
||||
&mut self,
|
||||
output: &mut dyn Write,
|
||||
name: &str,
|
||||
value: usize,
|
||||
comment: Option<&str>,
|
||||
indentation: Option<usize>,
|
||||
) -> Result<()> {
|
||||
let indentation = " ".repeat(indentation.unwrap_or(4));
|
||||
|
||||
let comment = comment.map_or(String::new(), |c| format!(" # {}", c));
|
||||
|
||||
write!(output, "{}{}: {}{}\n", indentation, name, value, comment)
|
||||
}
|
||||
|
||||
fn write_closure(&mut self, _output: &mut dyn Write, _eof: bool) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user