Make the FieldsIdsMap serialization more stable by using a BTreeMap

This commit is contained in:
Clément Renault 2020-10-22 14:23:33 +02:00
parent 9133f38138
commit 566a7c3039
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
9 changed files with 67 additions and 77 deletions

View file

@ -1,9 +1,9 @@
use std::collections::{HashMap, BTreeMap};
use std::collections::BTreeMap;
use serde::{Serialize, Deserialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FieldsIdsMap {
names_ids: HashMap<String, u8>,
names_ids: BTreeMap<String, u8>,
ids_names: BTreeMap<u8, String>,
next_id: Option<u8>,
}
@ -11,7 +11,7 @@ pub struct FieldsIdsMap {
impl FieldsIdsMap {
pub fn new() -> FieldsIdsMap {
FieldsIdsMap {
names_ids: HashMap::new(),
names_ids: BTreeMap::new(),
ids_names: BTreeMap::new(),
next_id: Some(0),
}
@ -66,6 +66,12 @@ impl FieldsIdsMap {
}
}
impl Default for FieldsIdsMap {
fn default() -> FieldsIdsMap {
FieldsIdsMap::new()
}
}
#[cfg(test)]
mod tests {
use super::*;