Skip to content

Commit 0baffdd

Browse files
authored
Minor fixes (#87)
* Move multipart classification into own closure * Add classification enum * Express classification indirectly with an enum * Express logic clause in equivalent way, add assert inline test to make sure of it * Remove old classifier * Remove enum indirection * Remove closure * Hoist common if condition into outer scope * Simplify expression * Simplify lifetime bounds A missing lifetime in the GetHeader trait was inferred by lifetime elision rules to be shorter than necessary, leading to awkward lifetime constraints being propagated throughout many functions that didnt need them. * Prohibit Rust 2018 idioms, return longest feasible lifetimes * Dont duplicate crlf in extension when saving failing results
1 parent 54ca7df commit 0baffdd

File tree

10 files changed

+86
-99
lines changed

10 files changed

+86
-99
lines changed

src/core/address.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'x> Address<'x> {
7373
}
7474

7575
/// Returns an iterator over the addresses in the list, or the addresses in the groups.
76-
pub fn iter<'y: 'x>(&'y self) -> Box<dyn DoubleEndedIterator<Item = &Addr<'x>> + 'x> {
76+
pub fn iter(&self) -> Box<dyn DoubleEndedIterator<Item = &Addr<'x>> + '_> {
7777
match self {
7878
Address::List(list) => Box::new(list.iter()),
7979
Address::Group(group) => {

src/core/header.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<'x> Header<'x> {
2626
}
2727

2828
/// Returns the parsed header value
29-
pub fn value(&self) -> &HeaderValue {
29+
pub fn value(&self) -> &HeaderValue<'x> {
3030
&self.value
3131
}
3232

@@ -171,14 +171,14 @@ impl<'x> HeaderValue<'x> {
171171
}
172172
}
173173

174-
pub fn as_received(&self) -> Option<&Received> {
174+
pub fn as_received(&self) -> Option<&Received<'x>> {
175175
match *self {
176176
HeaderValue::Received(ref r) => Some(r),
177177
_ => None,
178178
}
179179
}
180180

181-
pub fn as_content_type(&self) -> Option<&ContentType> {
181+
pub fn as_content_type(&self) -> Option<&ContentType<'x>> {
182182
match *self {
183183
HeaderValue::ContentType(ref c) => Some(c),
184184
_ => None,
@@ -374,7 +374,7 @@ impl<'x> HeaderName<'x> {
374374
}
375375
}
376376

377-
pub fn as_str<'y: 'x>(&'y self) -> &'x str {
377+
pub fn as_str(&self) -> &str {
378378
match self {
379379
HeaderName::Other(other) => other.as_ref(),
380380
_ => self.as_static_str(),
@@ -542,7 +542,7 @@ impl<'x> MimeHeaders<'x> for Message<'x> {
542542
.and_then(|header| header.as_text())
543543
}
544544

545-
fn content_disposition(&self) -> Option<&ContentType> {
545+
fn content_disposition(&self) -> Option<&ContentType<'x>> {
546546
self.parts[0]
547547
.headers
548548
.header_value(&HeaderName::ContentDisposition)
@@ -563,14 +563,14 @@ impl<'x> MimeHeaders<'x> for Message<'x> {
563563
.and_then(|header| header.as_text())
564564
}
565565

566-
fn content_type(&self) -> Option<&ContentType> {
566+
fn content_type(&self) -> Option<&ContentType<'x>> {
567567
self.parts[0]
568568
.headers
569569
.header_value(&HeaderName::ContentType)
570570
.and_then(|header| header.as_content_type())
571571
}
572572

573-
fn content_language(&self) -> &HeaderValue {
573+
fn content_language(&self) -> &HeaderValue<'x> {
574574
self.parts[0]
575575
.headers
576576
.header_value(&HeaderName::ContentLanguage)
@@ -667,7 +667,7 @@ impl<'x> MessagePart<'x> {
667667
}
668668

669669
/// Get the message headers
670-
pub fn headers(&self) -> &[Header] {
670+
pub fn headers(&self) -> &[Header<'x>] {
671671
&self.headers
672672
}
673673

@@ -713,7 +713,7 @@ impl<'x> MessagePart<'x> {
713713
}
714714

715715
impl<'x> fmt::Display for MessagePart<'x> {
716-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
716+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
717717
fmt.write_str(self.text_contents().unwrap_or("[no contents]"))
718718
}
719719
}
@@ -725,7 +725,7 @@ impl<'x> MimeHeaders<'x> for MessagePart<'x> {
725725
.and_then(|header| header.as_text())
726726
}
727727

728-
fn content_disposition(&self) -> Option<&ContentType> {
728+
fn content_disposition(&self) -> Option<&ContentType<'x>> {
729729
self.headers
730730
.header_value(&HeaderName::ContentDisposition)
731731
.and_then(|header| header.as_content_type())
@@ -743,13 +743,13 @@ impl<'x> MimeHeaders<'x> for MessagePart<'x> {
743743
.and_then(|header| header.as_text())
744744
}
745745

746-
fn content_type(&self) -> Option<&ContentType> {
746+
fn content_type(&self) -> Option<&ContentType<'x>> {
747747
self.headers
748748
.header_value(&HeaderName::ContentType)
749749
.and_then(|header| header.as_content_type())
750750
}
751751

752-
fn content_language(&self) -> &HeaderValue {
752+
fn content_language(&self) -> &HeaderValue<'x> {
753753
self.headers
754754
.header_value(&HeaderName::ContentLanguage)
755755
.unwrap_or(&HeaderValue::Empty)
@@ -786,7 +786,7 @@ impl<'x> ContentType<'x> {
786786
}
787787

788788
/// Removes an attribute by name
789-
pub fn remove_attribute(&mut self, name: &str) -> Option<Cow<str>> {
789+
pub fn remove_attribute(&mut self, name: &str) -> Option<Cow<'x, str>> {
790790
let attributes = self.attributes.as_mut()?;
791791

792792
attributes
@@ -796,15 +796,15 @@ impl<'x> ContentType<'x> {
796796
}
797797

798798
/// Returns all attributes
799-
pub fn attributes(&self) -> Option<&[(Cow<str>, Cow<str>)]> {
799+
pub fn attributes(&self) -> Option<&[(Cow<'x, str>, Cow<'x, str>)]> {
800800
self.attributes.as_deref()
801801
}
802802

803803
/// Returns `true` when the provided attribute name is present
804804
pub fn has_attribute(&self, name: &str) -> bool {
805805
self.attributes
806806
.as_ref()
807-
.map_or_else(|| false, |attr| attr.iter().any(|(key, _)| key == name))
807+
.map_or(false, |attr| attr.iter().any(|(key, _)| key == name))
808808
}
809809

810810
/// Returns ```true``` if the Content-Disposition type is "attachment"
@@ -840,7 +840,7 @@ impl<'x> Received<'x> {
840840
}
841841

842842
/// Returns the hostname or IP address of the machine that originated the message
843-
pub fn from(&self) -> Option<&Host> {
843+
pub fn from(&self) -> Option<&Host<'x>> {
844844
self.from.as_ref()
845845
}
846846

@@ -855,7 +855,7 @@ impl<'x> Received<'x> {
855855
}
856856

857857
/// Returns the hostname or IP address of the machine that received the message
858-
pub fn by(&self) -> Option<&Host> {
858+
pub fn by(&self) -> Option<&Host<'x>> {
859859
self.by.as_ref()
860860
}
861861

@@ -890,7 +890,7 @@ impl<'x> Received<'x> {
890890
}
891891

892892
/// Returns the EHLO/LHLO/HELO hostname or IP address of the machine that sent the message
893-
pub fn helo(&self) -> Option<&Host> {
893+
pub fn helo(&self) -> Option<&Host<'x>> {
894894
self.helo.as_ref()
895895
}
896896

@@ -921,14 +921,14 @@ impl<'x> Host<'x> {
921921
}
922922

923923
impl<'x> GetHeader<'x> for Vec<Header<'x>> {
924-
fn header_value(&self, name: &HeaderName) -> Option<&HeaderValue<'x>> {
924+
fn header_value(&self, name: &HeaderName<'_>) -> Option<&HeaderValue<'x>> {
925925
self.iter()
926926
.rev()
927927
.find(|header| &header.name == name)
928928
.map(|header| &header.value)
929929
}
930930

931-
fn header(&self, name: impl Into<HeaderName<'x>>) -> Option<&Header> {
931+
fn header(&self, name: impl Into<HeaderName<'x>>) -> Option<&Header<'x>> {
932932
let name = name.into();
933933
self.iter().rev().find(|header| header.name == name)
934934
}
@@ -953,7 +953,7 @@ impl<'x> From<String> for HeaderName<'x> {
953953
}
954954

955955
impl From<HeaderName<'_>> for String {
956-
fn from(header: HeaderName) -> Self {
956+
fn from(header: HeaderName<'_>) -> Self {
957957
header.to_string()
958958
}
959959
}

0 commit comments

Comments
 (0)