summaryrefslogtreecommitdiffstats
path: root/template/src/additional_cid.rs
diff options
context:
space:
mode:
Diffstat (limited to 'template/src/additional_cid.rs')
-rw-r--r--template/src/additional_cid.rs37
1 files changed, 22 insertions, 15 deletions
diff --git a/template/src/additional_cid.rs b/template/src/additional_cid.rs
index eecf2e7..7d17d4b 100644
--- a/template/src/additional_cid.rs
+++ b/template/src/additional_cid.rs
@@ -1,6 +1,4 @@
-use std::collections::{
- HashMap, HashSet
-};
+use std::collections::{HashMap, HashSet};
use serde::{Serialize, Serializer};
@@ -8,20 +6,20 @@ use mail_core::Resource;
use mail_headers::header_components::ContentId;
pub struct AdditionalCIds<'a> {
- additional_resources: &'a [&'a HashMap<String, Resource>]
+ additional_resources: &'a [&'a HashMap<String, Resource>],
}
impl<'a> AdditionalCIds<'a> {
-
/// Creates a new `AdditionalCIds` instance.
///
/// All resources in the all hash maps have to be loaded to the
/// `Data` or `EncData` variants or using `get` can panic.
pub(crate) fn new(additional_resources: &'a [&'a HashMap<String, Resource>]) -> Self {
- AdditionalCIds { additional_resources }
+ AdditionalCIds {
+ additional_resources,
+ }
}
-
/// Returns the content id associated with the given name.
///
/// If multiple of the maps used to create this type contain the
@@ -35,7 +33,10 @@ impl<'a> AdditionalCIds<'a> {
pub fn get(&self, name: &str) -> Option<&ContentId> {
for possible_source in self.additional_resources {
if let Some(res) = possible_source.get(name) {
- return Some(res.content_id().expect("all resources should be loaded/have a content id"));
+ return Some(
+ res.content_id()
+ .expect("all resources should be loaded/have a content id"),
+ );
}
}
return None;
@@ -44,17 +45,23 @@ impl<'a> AdditionalCIds<'a> {
impl<'a> Serialize for AdditionalCIds<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
- where S: Serializer
+ where
+ S: Serializer,
{
let mut existing_keys = HashSet::new();
serializer.collect_map(
self.additional_resources
- .iter()
- .flat_map(|m| m.iter().map(|(k, resc)| {
- (k, resc.content_id().expect("all resources should be loaded/have a content id"))
- }))
- .filter(|key| existing_keys.insert(key.to_owned()))
+ .iter()
+ .flat_map(|m| {
+ m.iter().map(|(k, resc)| {
+ (
+ k,
+ resc.content_id()
+ .expect("all resources should be loaded/have a content id"),
+ )
+ })
+ })
+ .filter(|key| existing_keys.insert(key.to_owned())),
)
}
}
-