Skip to content

Commit

Permalink
chore: use IndexMap instead of HashMap
Browse files Browse the repository at this point in the history
  • Loading branch information
KianNH committed Oct 13, 2022
1 parent 7db5c2f commit 16647d2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ serde = { version = "1.0.145", features = ["derive"] }
serde_json = "1.0.86"
glob = "0.3.0"
clap = { version = "4.0.14", features = ["derive"] }
indexmap = { version = "1.9.1", features = ["serde"] }
11 changes: 7 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ use serde::Serialize;
use capnpc::schema_capnp::value;
use glob::glob;
use clap::Parser;
use indexmap::IndexMap;

#[derive(Serialize)]
struct Field {
name: String,
annotations: HashMap<String, String>,
#[serde(with = "indexmap::serde_seq")]
annotations: IndexMap<String, String>
}

#[derive(Serialize)]
Expand Down Expand Up @@ -102,6 +104,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let node_name = node.get_display_name()?;
let prefix_len = node.get_display_name_prefix_length() as usize;
let annotation_name = node_name[prefix_len..].to_string();

let id = node.get_id();
annotation_names.insert(id.to_string(), annotation_name);
}
Expand All @@ -125,7 +128,7 @@ fn main() -> Result<(), Box<dyn Error>> {

println!(" field: {field_name}");
results.structs[idx].fields.push(
Field { name: field_name, annotations: HashMap::new() }
Field { name: field_name, annotations: IndexMap::new() }
);

let annotations = field.get_annotations()?;
Expand Down Expand Up @@ -154,7 +157,7 @@ fn main() -> Result<(), Box<dyn Error>> {

println!(" enumerant: {enumerant_name}");
results.enums[idx].enumerants.push(
Field { name: enumerant_name, annotations: HashMap::new() }
Field { name: enumerant_name, annotations: IndexMap::new() }
);

let annotations = enumerant.get_annotations()?;
Expand Down Expand Up @@ -183,7 +186,7 @@ fn main() -> Result<(), Box<dyn Error>> {

println!(" method: {method_name}");
results.interfaces[idx].methods.push(
Field { name: method_name, annotations: HashMap::new() }
Field { name: method_name, annotations: IndexMap::new() }
);

let annotations = method.get_annotations()?;
Expand Down

0 comments on commit 16647d2

Please sign in to comment.