Release 1.1.4

This commit is contained in:
a2x
2023-10-26 15:41:34 +10:00
parent 631668429c
commit 239c872b65
37 changed files with 1905 additions and 1308 deletions

View File

@@ -1,27 +1,27 @@
use std::{
collections::BTreeMap,
io::{Result, Write},
};
use super::FileBuilder;
use serde::Serialize;
use super::FileBuilder;
use std::collections::BTreeMap;
use std::io::{Result, Write};
/// Represents an offset value in JSON format.
/// Represents a JSON offset value with an optional comment.
#[derive(Debug, PartialEq, Default, Serialize)]
struct JsonOffsetValue {
value: usize,
comment: Option<String>,
}
/// Represents a module in JSON format.
/// Represents a JSON module, which contains data in the form of a `BTreeMap` of string keys and
/// `JsonOffsetValue` values, as well as an optional comment.
#[derive(Debug, PartialEq, Default, Serialize)]
struct JsonModule {
data: BTreeMap<String, JsonOffsetValue>,
comment: Option<String>,
}
/// Represents a JSON file builder.
/// A structure representing a builder for JSON files.
/// The builder implements the `FileBuilder` trait.
#[derive(Debug, PartialEq, Default)]
pub struct JsonFileBuilder {
data: BTreeMap<String, JsonModule>,
@@ -43,8 +43,8 @@ impl FileBuilder for JsonFileBuilder {
name: &str,
comment: Option<&str>,
) -> Result<()> {
self.current_namespace = name.to_string();
self.data.entry(name.to_string()).or_default().comment = comment.map(str::to_string);
self.current_namespace = name.to_string();
Ok(())
}
@@ -55,6 +55,7 @@ impl FileBuilder for JsonFileBuilder {
name: &str,
value: usize,
comment: Option<&str>,
_indentation: Option<usize>,
) -> Result<()> {
self.data
.entry(self.current_namespace.clone())
@@ -63,7 +64,7 @@ impl FileBuilder for JsonFileBuilder {
.insert(
name.to_string(),
JsonOffsetValue {
value: value,
value,
comment: comment.map(str::to_string),
},
);
@@ -75,7 +76,7 @@ impl FileBuilder for JsonFileBuilder {
if eof {
write!(output, "{}", serde_json::to_string_pretty(&self.data)?)?;
self.data = BTreeMap::new();
self.data.clear();
}
Ok(())