Skip to content

Commit b950fce

Browse files
committed
melib: Use IndexMap in VCard
Signed-off-by: Manos Pitsidianakis <[email protected]>
1 parent 65b32e7 commit b950fce

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

melib/src/addressbook/vcard.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
//! - Version 4 [RFC 6350: vCard Format Specification](https://datatracker.ietf.org/doc/rfc6350/)
2828
//! - Parameter escaping [RFC 6868 Parameter Value Encoding in iCalendar and vCard](https://datatracker.ietf.org/doc/rfc6868/)
2929
30-
use std::{collections::HashMap, convert::TryInto};
30+
use std::convert::TryInto;
31+
32+
use indexmap::IndexMap;
3133

3234
use super::*;
3335
use crate::{
@@ -63,14 +65,14 @@ const FOOTER: &str = "END:VCARD";
6365

6466
#[derive(Debug)]
6567
pub struct VCard<T: VCardVersion>(
66-
HashMap<String, ContentLine>,
68+
IndexMap<String, ContentLine>,
6769
std::marker::PhantomData<*const T>,
6870
);
6971

7072
impl<V: VCardVersion> VCard<V> {
7173
pub fn new_v4() -> VCard<impl VCardVersion> {
7274
VCard(
73-
HashMap::default(),
75+
IndexMap::default(),
7476
std::marker::PhantomData::<*const VCardVersion4>,
7577
)
7678
}
@@ -106,7 +108,7 @@ impl CardDeserializer {
106108
&input[HEADER_LF.len()..input.len() - FOOTER_LF.len()]
107109
};
108110

109-
let mut ret = HashMap::default();
111+
let mut ret = IndexMap::default();
110112

111113
enum Stage {
112114
Group,
@@ -198,15 +200,15 @@ impl<V: VCardVersion> TryInto<Card> for VCard<V> {
198200
}
199201
hasher.finish()
200202
}));
201-
if let Some(val) = self.0.remove("FN") {
203+
if let Some(val) = self.0.swap_remove("FN") {
202204
card.set_name(val.value);
203205
} else {
204206
return Err(Error::new("FN entry missing in VCard.").set_kind(ErrorKind::ValueError));
205207
}
206-
if let Some(val) = self.0.remove("NICKNAME") {
208+
if let Some(val) = self.0.swap_remove("NICKNAME") {
207209
card.set_additionalname(val.value);
208210
}
209-
if let Some(val) = self.0.remove("BDAY") {
211+
if let Some(val) = self.0.swap_remove("BDAY") {
210212
/* 4.3.4. DATE-AND-OR-TIME
211213
212214
Either a DATE-TIME, a DATE, or a TIME value. To allow unambiguous
@@ -234,13 +236,13 @@ impl<V: VCardVersion> TryInto<Card> for VCard<V> {
234236
crate::utils::datetime::timestamp_from_string(val.value.as_str(), "%Y%m%d\0")
235237
.unwrap_or_default();
236238
}
237-
if let Some(val) = self.0.remove("EMAIL") {
239+
if let Some(val) = self.0.swap_remove("EMAIL") {
238240
card.set_email(val.value);
239241
}
240-
if let Some(val) = self.0.remove("URL") {
242+
if let Some(val) = self.0.swap_remove("URL") {
241243
card.set_url(val.value);
242244
}
243-
if let Some(val) = self.0.remove("KEY") {
245+
if let Some(val) = self.0.swap_remove("KEY") {
244246
card.set_key(val.value);
245247
}
246248
for (k, v) in self.0.into_iter() {

0 commit comments

Comments
 (0)