diff options
author | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2025-03-18 11:31:19 +0700 |
---|---|---|
committer | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2025-03-18 11:31:19 +0700 |
commit | 52b0d3db1289a74aa4817b211c3fcbf0bba84a99 (patch) | |
tree | 3eeccc3b497d0e49f39a37c91073fec39d8bd9e7 /src/utilities.rs | |
parent | 2766f230eff64b63cf4c88e8c26019762a92494d (diff) |
upd: replace HashMap to IndexMap to preserve header's order
Diffstat (limited to 'src/utilities.rs')
-rw-r--r-- | src/utilities.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/utilities.rs b/src/utilities.rs index 8f80ecd..1a19f20 100644 --- a/src/utilities.rs +++ b/src/utilities.rs @@ -1,3 +1,4 @@ +use indexmap::IndexMap; use std::collections::HashMap; use std::path::PathBuf; @@ -50,14 +51,14 @@ pub fn path_should_not_exist(path: &PathBuf, message: &str) { } } -pub fn deserialize_kv_with_message(data: &Vec<u8>) -> (HashMap<String, String>, String) { +pub fn deserialize_kv_with_message(data: &Vec<u8>) -> (IndexMap<String, String>, String) { let string_rep = String::from_utf8(data.clone()); if string_rep.is_err() { die!("Failed to parse commit data"); } let string_rep = string_rep.unwrap(); let mut is_message = false; - let mut header: HashMap<String, String> = HashMap::new(); + let mut header: IndexMap<String, String> = IndexMap::new(); let mut message = String::new(); let mut last_key: Option<String> = None; for line in string_rep.lines() { @@ -95,3 +96,9 @@ pub fn deserialize_kv_with_message(data: &Vec<u8>) -> (HashMap<String, String>, } (header, message) } + +pub fn serialize_kv_with_message(header: &HashMap<String, String>, message: &str) { + for (key, val) in header.into_iter() { + + } +} |