diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-12-23 12:51:54 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-12-23 12:51:54 +0100 |
commit | 31193c2bef934d26265673c91cbea0b64a53cd15 (patch) | |
tree | 105163b13ed6fcb43e655f233679cc5947cf0b7b | |
parent | 71ea078d4eb5d857680a69b01f7427ea43e2f5a2 (diff) |
Run cargo-fmt on codebasecargo-fmt
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
92 files changed, 3304 insertions, 3701 deletions
diff --git a/core/examples/readme.rs b/core/examples/readme.rs index 5e0cd42..7f2c0ed 100644 --- a/core/examples/readme.rs +++ b/core/examples/readme.rs @@ -6,24 +6,17 @@ extern crate mail_internals; #[macro_use] extern crate mail_headers; -use std::str; use futures::Future; +use std::str; use mail_internals::MailType; // In the facade this is the `headers` module. -use mail_headers::{ - headers::*, - header_components::Domain -}; +use mail_headers::{header_components::Domain, headers::*}; // In the facade this types (and the default_impl module) // are also exposed at top level -use mail_core::{ - Mail, - default_impl::simple_context, - error::MailError -}; +use mail_core::{default_impl::simple_context, error::MailError, Mail}; fn print_some_mail() -> Result<(), MailError> { // Domain will implement `from_str` in the future, @@ -43,7 +36,8 @@ fn print_some_mail() -> Result<(), MailError> { // We don't added any think which needs loading but we could have // and all of it would have been loaded concurrent and async. - let encoded = mail.into_encodable_mail(ctx.clone()) + let encoded = mail + .into_encodable_mail(ctx.clone()) .wait()? .encode_into_bytes(MailType::Ascii)?; @@ -54,4 +48,4 @@ fn print_some_mail() -> Result<(), MailError> { fn main() { print_some_mail().unwrap() -}
\ No newline at end of file +} diff --git a/core/src/compose.rs b/core/src/compose.rs index 1334a22..e69317b 100644 --- a/core/src/compose.rs +++ b/core/src/compose.rs @@ -17,23 +17,15 @@ // in the later part of the file for better readability. || //-------------------------------------------------------------// -use media_type::{MULTIPART, ALTERNATIVE, RELATED, MIXED}; +use media_type::{ALTERNATIVE, MIXED, MULTIPART, RELATED}; use vec1::Vec1; use headers::{ - HeaderKind, - headers, - header_components::{ - Disposition, - DispositionKind, - MediaType - } + header_components::{Disposition, DispositionKind, MediaType}, + headers, HeaderKind, }; -use crate::{ - mail::Mail, - resource::Resource -}; +use crate::{mail::Mail, resource::Resource}; /// Parts used to create a mail body (in a multipart mail). /// @@ -45,7 +37,6 @@ use crate::{ /// by it's content id. #[derive(Debug)] pub struct BodyPart { - /// A body created by a template. pub resource: Resource, @@ -68,8 +59,7 @@ pub struct BodyPart { /// Attachments of a `BodyPart` instance will be combined with /// the attachments of other instances and the ones in the /// `MailParts` instance. - pub attachments: Vec<Resource> - + pub attachments: Vec<Resource>, } /// Parts which can be used to compose a multipart mail. @@ -116,17 +106,14 @@ pub struct MailParts { pub inline_embeddings: Vec<Resource>, /// A number of embeddings which should be treated as attachments - pub attachments: Vec<Resource> + pub attachments: Vec<Resource>, } //-------------------------------------------------------\\ // implementations for creating mails are from here on || //-------------------------------------------------------// - impl MailParts { - - /// Create a `Mail` instance based on this `MailParts` instance. /// /// @@ -151,57 +138,52 @@ impl MailParts { /// Each sub-body created for a `BodyPart` will be wrapped /// inside a `multipart/related` if it has body specific /// embeddings (with content disposition inline). - pub fn compose(self) - -> Mail - { + pub fn compose(self) -> Mail { let MailParts { alternative_bodies, inline_embeddings, - attachments + attachments, } = self; - let mut attachments = attachments.into_iter() + let mut attachments = attachments + .into_iter() .map(|atta| atta.create_mail_with_disposition(DispositionKind::Attachment)) .collect::<Vec<_>>(); - let mut alternatives = alternative_bodies.into_iter() + let mut alternatives = alternative_bodies + .into_iter() .map(|body| body.create_mail(&mut attachments)) .collect::<Vec<_>>(); //UNWRAP_SAFE: bodies is Vec1, i.e. we have at last one let mail = alternatives.pop().unwrap(); - let mail = - if alternatives.is_empty() { - mail - } else { - mail.wrap_with_alternatives(alternatives) - }; + let mail = if alternatives.is_empty() { + mail + } else { + mail.wrap_with_alternatives(alternatives) + }; - let mail = - if inline_embeddings.is_empty() { - mail - } else { - let related = inline_embeddings.into_iter() - .map(|embedding| { - embedding.create_mail_with_disposition(DispositionKind::Inline) - }) - .collect::<Vec<_>>(); - mail.wrap_with_related(related) - }; + let mail = if inline_embeddings.is_empty() { + mail + } else { + let related = inline_embeddings + .into_iter() + .map(|embedding| embedding.create_mail_with_disposition(DispositionKind::Inline)) + .collect::<Vec<_>>(); + mail.wrap_with_related(related) + }; - let mail = - if attachments.is_empty() { - mail - } else { - mail.wrap_with_mixed(attachments) - }; + let mail = if attachments.is_empty() { + mail + } else { + mail.wrap_with_mixed(attachments) + }; mail } } impl BodyPart { - /// Creates a `Mail` instance from this `BodyPart` instance. /// /// All embeddings in `BodyPart.embeddings` which have a @@ -215,14 +197,11 @@ impl BodyPart { /// have a `Inline` disposition that body will be /// wrapped into a `multipart/related` body containing /// them. - pub fn create_mail( - self, - attachments_out: &mut Vec<Mail>, - ) -> Mail { + pub fn create_mail(self, attachments_out: &mut Vec<Mail>) -> Mail { let BodyPart { resource, inline_embeddings, - attachments + attachments, } = self; let body = resource.create_mail(); @@ -235,10 +214,9 @@ impl BodyPart { if inline_embeddings.is_empty() { body } else { - let related = inline_embeddings.into_iter() - .map(|embedding| { - embedding.create_mail_with_disposition(DispositionKind::Inline) - }) + let related = inline_embeddings + .into_iter() + .map(|embedding| embedding.create_mail_with_disposition(DispositionKind::Inline)) .collect::<Vec<_>>(); body.wrap_with_related(related) } @@ -246,7 +224,6 @@ impl BodyPart { } impl Resource { - /// Create a `Mail` instance representing this `Resource`. /// /// This is not a complete mail, i.e. it will not contain @@ -268,15 +245,12 @@ impl Resource { } impl Mail { - /// Create a `multipart/mixed` `Mail` instance containing this mail as /// first body and one additional body for each attachment. /// /// Normally this is used with embeddings having a attachment /// disposition creating a mail with attachments. - pub fn wrap_with_mixed(self, other_bodies: Vec<Mail>) - -> Mail - { + pub fn wrap_with_mixed(self, other_bodies: Vec<Mail>) -> Mail { let mut bodies = other_bodies; bodies.push(self); new_multipart(&MIXED, bodies) @@ -291,9 +265,7 @@ impl Mail { /// specified by `multipart/alternative`. /// This also means that _this_ body will be the last body as it is /// meant to be the _main_ body. - pub fn wrap_with_alternatives(self, alternates: Vec<Mail>) - -> Mail - { + pub fn wrap_with_alternatives(self, alternates: Vec<Mail>) -> Mail { let mut bodies = alternates; //TODO[opt] accept iter and prepend instead of insert in vec bodies.insert(0, self); @@ -302,14 +274,11 @@ impl Mail { /// Creates a `multipart/related` `Mail` instance containing this /// mail first and then all related bodies. - pub fn wrap_with_related(self, related: Vec<Mail>) - -> Mail - { + pub fn wrap_with_related(self, related: Vec<Mail>) -> Mail { let mut bodies = related; bodies.insert(0, self); new_multipart(&RELATED, bodies) } - } /// Creates a `multipart/<sub_type>` mail with given bodies. @@ -318,10 +287,7 @@ impl Mail { /// /// If `sub_type` can not be used to create a multipart content /// type this will panic. -fn new_multipart(sub_type: &'static str, bodies: Vec<Mail>) - -> Mail -{ - let content_type = MediaType::new(MULTIPART, sub_type) - .unwrap(); +fn new_multipart(sub_type: &'static str, bodies: Vec<Mail>) -> Mail { + let content_type = MediaType::new(MULTIPART, sub_type).unwrap(); Mail::new_multipart_mail(content_type, bodies) -}
\ No newline at end of file +} diff --git a/core/src/context.rs b/core/src/context.rs index 88f1045..d776da5 100644 --- a/core/src/context.rs +++ b/core/src/context.rs @@ -1,44 +1,46 @@ //! Provides the context needed for building/encoding mails. -use std::sync::Arc; use std::fmt::Debug; +use std::sync::Arc; -use futures::{ future::{self, Either}, Future, IntoFuture }; +use futures::{ + future::{self, Either}, + Future, IntoFuture, +}; use utils::SendBoxFuture; -use headers::header_components::{ - MessageId, ContentId -}; +use headers::header_components::{ContentId, MessageId}; use crate::{ - resource::{Source, Data, EncData, Resource}, - error::ResourceLoadingError + error::ResourceLoadingError, + resource::{Data, EncData, Resource, Source}, }; - /// Represents Data which might already have been transfer encoded. pub enum MaybeEncData { /// The data is returned normally. Data(Data), /// The data is returned in a already transfer encoded variant. - EncData(EncData) + EncData(EncData), } impl MaybeEncData { - pub fn to_resource(self) -> Resource { match self { MaybeEncData::Data(data) => Resource::Data(data), - MaybeEncData::EncData(enc_data) => Resource::EncData(enc_data) + MaybeEncData::EncData(enc_data) => Resource::EncData(enc_data), } } - pub fn encode(self, ctx: &impl Context) - -> impl Future<Item=EncData,Error=ResourceLoadingError> - { + pub fn encode( + self, + ctx: &impl Context, + ) -> impl Future<Item = EncData, Error = ResourceLoadingError> { match self { - MaybeEncData::Data(data) => Either::A(ctx.load_transfer_encoded_resource(&Resource::Data(data))), - MaybeEncData::EncData(enc) => Either::B(future::ok(enc)) + MaybeEncData::Data(data) => { + Either::A(ctx.load_transfer_encoded_resource(&Resource::Data(data))) + } + MaybeEncData::EncData(enc) => Either::B(future::ok(enc)), } } } @@ -76,8 +78,6 @@ impl MaybeEncData { /// implementor to have a outer+inner type where the inner type is wrapped /// into a `Arc` e.g. `struct SomeCtx { inner: Arc<InnerSomeCtx> }`. pub trait Context: Debug + Clone + Send + Sync + 'static { - - /// Loads and transfer encodes a `Data` instance. /// /// This is called when a `Mail` instance is converted into @@ -98,8 +98,7 @@ pub trait Context: Debug + Clone + Send + Sync + 'static { /// This function should not block and schedule the encoding /// in some other place e.g. by using the contexts offload /// functionality. - fn load_resource(&self, source: &Source) - -> SendBoxFuture<MaybeEncData, ResourceLoadingError>; + fn load_resource(&self, source: &Source) -> SendBoxFuture<MaybeEncData, ResourceLoadingError>; /// Loads and Transfer encodes a `Resource` instance. /// @@ -124,9 +123,10 @@ pub trait Context: Debug + Clone + Send + Sync + 'static { /// This function should not block and schedule the encoding /// in some other place e.g. by using the contexts offload /// functionality. - fn load_transfer_encoded_resource(&self, resource: &Resource) - -> SendBoxFuture<EncData, ResourceLoadingError> - { + fn load_transfer_encoded_resource( + &self, + resource: &Resource, + ) -> SendBoxFuture<EncData, ResourceLoadingError> { default_impl_for_load_transfer_encoded_resource(self, resource) } @@ -161,60 +161,56 @@ pub trait Context: Debug + Clone + Send + Sync + 'static { //TODO[futures/v>=0.2]: integrate this with Context /// offloads the execution of the future `fut` to somewhere else e.g. a cpu pool fn offload<F>(&self, fut: F) -> SendBoxFuture<F::Item, F::Error> - where F: Future + Send + 'static, - F::Item: Send + 'static, - F::Error: Send + 'static; + where + F: Future + Send + 'static, + F::Item: Send + 'static, + F::Error: Send + 'static; //TODO[futures/v>=0.2]: integrate this with Context /// offloads the execution of the function `func` to somewhere else e.g. a cpu pool - fn offload_fn<FN, I>(&self, func: FN ) -> SendBoxFuture<I::Item, I::Error> - where FN: FnOnce() -> I + Send + 'static, - I: IntoFuture + 'static, - I::Future: Send + 'static, - I::Item: Send + 'static, - I::Error: Send + 'static + fn offload_fn<FN, I>(&self, func: FN) -> SendBoxFuture<I::Item, I::Error> + where + FN: FnOnce() -> I + Send + 'static, + I: IntoFuture + 'static, + I::Future: Send + 'static, + I::Item: Send + 'static, + I::Error: Send + 'static, { - self.offload( future::lazy( func ) ) + self.offload(future::lazy(func)) |