Skip to content

Commit 64bc753

Browse files
committed
Prohibit Rust 2018 idioms, return longest feasible lifetimes
1 parent 0e7db16 commit 64bc753

File tree

9 files changed

+51
-50
lines changed

9 files changed

+51
-50
lines changed

src/core/header.rs

Lines changed: 17 additions & 17 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,
@@ -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,7 +796,7 @@ 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

@@ -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

@@ -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
}

src/core/message.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ impl<'x> Message<'x> {
2929
}
3030

3131
/// Returns a parsed header.
32-
pub fn header(&self, header: impl Into<HeaderName<'x>>) -> Option<&HeaderValue> {
32+
pub fn header(&self, header: impl Into<HeaderName<'x>>) -> Option<&HeaderValue<'x>> {
3333
self.parts[0].headers.header(header).map(|h| &h.value)
3434
}
3535

3636
/// Removed a parsed header and returns its value.
37-
pub fn remove_header(&mut self, header: impl Into<HeaderName<'x>>) -> Option<HeaderValue> {
37+
pub fn remove_header(&mut self, header: impl Into<HeaderName<'x>>) -> Option<HeaderValue<'x>> {
3838
let header = header.into();
3939
let headers = &mut self.parts[0].headers;
4040
headers
@@ -56,7 +56,7 @@ impl<'x> Message<'x> {
5656
&self,
5757
header: impl Into<HeaderName<'x>>,
5858
form: HeaderForm,
59-
) -> Vec<HeaderValue> {
59+
) -> Vec<HeaderValue<'_>> {
6060
let header = header.into();
6161
let mut results = Vec::new();
6262
for header_ in &self.parts[0].headers {
@@ -85,7 +85,7 @@ impl<'x> Message<'x> {
8585
}
8686

8787
/// Returns an iterator over the RFC headers of this message.
88-
pub fn headers(&self) -> &[Header] {
88+
pub fn headers(&self) -> &[Header<'x>] {
8989
&self.parts[0].headers
9090
}
9191

@@ -140,7 +140,7 @@ impl<'x> Message<'x> {
140140
}
141141

142142
/// Returns all Comments header fields
143-
pub fn comments(&self) -> &HeaderValue {
143+
pub fn comments(&self) -> &HeaderValue<'x> {
144144
self.parts[0]
145145
.headers
146146
.header_value(&HeaderName::Comments)
@@ -164,71 +164,71 @@ impl<'x> Message<'x> {
164164
}
165165

166166
/// Returns all In-Reply-To header fields
167-
pub fn in_reply_to(&self) -> &HeaderValue {
167+
pub fn in_reply_to(&self) -> &HeaderValue<'x> {
168168
self.parts[0]
169169
.headers
170170
.header_value(&HeaderName::InReplyTo)
171171
.unwrap_or(&HeaderValue::Empty)
172172
}
173173

174174
/// Returns all Keywords header fields
175-
pub fn keywords(&self) -> &HeaderValue {
175+
pub fn keywords(&self) -> &HeaderValue<'x> {
176176
self.parts[0]
177177
.headers
178178
.header_value(&HeaderName::Keywords)
179179
.unwrap_or(&HeaderValue::Empty)
180180
}
181181

182182
/// Returns the List-Archive header field
183-
pub fn list_archive(&self) -> &HeaderValue {
183+
pub fn list_archive(&self) -> &HeaderValue<'x> {
184184
self.parts[0]
185185
.headers
186186
.header_value(&HeaderName::ListArchive)
187187
.unwrap_or(&HeaderValue::Empty)
188188
}
189189

190190
/// Returns the List-Help header field
191-
pub fn list_help(&self) -> &HeaderValue {
191+
pub fn list_help(&self) -> &HeaderValue<'x> {
192192
self.parts[0]
193193
.headers
194194
.header_value(&HeaderName::ListHelp)
195195
.unwrap_or(&HeaderValue::Empty)
196196
}
197197

198198
/// Returns the List-ID header field
199-
pub fn list_id(&self) -> &HeaderValue {
199+
pub fn list_id(&self) -> &HeaderValue<'x> {
200200
self.parts[0]
201201
.headers
202202
.header_value(&HeaderName::ListId)
203203
.unwrap_or(&HeaderValue::Empty)
204204
}
205205

206206
/// Returns the List-Owner header field
207-
pub fn list_owner(&self) -> &HeaderValue {
207+
pub fn list_owner(&self) -> &HeaderValue<'x> {
208208
self.parts[0]
209209
.headers
210210
.header_value(&HeaderName::ListOwner)
211211
.unwrap_or(&HeaderValue::Empty)
212212
}
213213

214214
/// Returns the List-Post header field
215-
pub fn list_post(&self) -> &HeaderValue {
215+
pub fn list_post(&self) -> &HeaderValue<'x> {
216216
self.parts[0]
217217
.headers
218218
.header_value(&HeaderName::ListPost)
219219
.unwrap_or(&HeaderValue::Empty)
220220
}
221221

222222
/// Returns the List-Subscribe header field
223-
pub fn list_subscribe(&self) -> &HeaderValue {
223+
pub fn list_subscribe(&self) -> &HeaderValue<'x> {
224224
self.parts[0]
225225
.headers
226226
.header_value(&HeaderName::ListSubscribe)
227227
.unwrap_or(&HeaderValue::Empty)
228228
}
229229

230230
/// Returns the List-Unsubscribe header field
231-
pub fn list_unsubscribe(&self) -> &HeaderValue {
231+
pub fn list_unsubscribe(&self) -> &HeaderValue<'x> {
232232
self.parts[0]
233233
.headers
234234
.header_value(&HeaderName::ListUnsubscribe)
@@ -244,23 +244,23 @@ impl<'x> Message<'x> {
244244
}
245245

246246
/// Returns the MIME-Version header field
247-
pub fn mime_version(&self) -> &HeaderValue {
247+
pub fn mime_version(&self) -> &HeaderValue<'x> {
248248
self.parts[0]
249249
.headers
250250
.header_value(&HeaderName::MimeVersion)
251251
.unwrap_or(&HeaderValue::Empty)
252252
}
253253

254254
/// Returns the first Received header field
255-
pub fn received(&self) -> Option<&Received> {
255+
pub fn received(&self) -> Option<&Received<'x>> {
256256
self.parts[0]
257257
.headers
258258
.header_value(&HeaderName::Received)
259259
.and_then(|header| header.as_received())
260260
}
261261

262262
/// Returns all References header fields
263-
pub fn references(&self) -> &HeaderValue {
263+
pub fn references(&self) -> &HeaderValue<'x> {
264264
self.parts[0]
265265
.headers
266266
.header_value(&HeaderName::References)
@@ -292,7 +292,7 @@ impl<'x> Message<'x> {
292292
}
293293

294294
/// Returns all Resent-Date header fields
295-
pub fn resent_date(&self) -> &HeaderValue {
295+
pub fn resent_date(&self) -> &HeaderValue<'x> {
296296
self.parts[0]
297297
.headers
298298
.header_value(&HeaderName::ResentDate)
@@ -308,7 +308,7 @@ impl<'x> Message<'x> {
308308
}
309309

310310
/// Returns all Resent-Message-ID header fields
311-
pub fn resent_message_id(&self) -> &HeaderValue {
311+
pub fn resent_message_id(&self) -> &HeaderValue<'x> {
312312
self.parts[0]
313313
.headers
314314
.header_value(&HeaderName::ResentMessageId)
@@ -332,7 +332,7 @@ impl<'x> Message<'x> {
332332
}
333333

334334
/// Returns all Return-Path header fields
335-
pub fn return_path(&self) -> &HeaderValue {
335+
pub fn return_path(&self) -> &HeaderValue<'x> {
336336
self.parts[0]
337337
.headers
338338
.header_value(&HeaderName::ReturnPath)
@@ -414,17 +414,17 @@ impl<'x> Message<'x> {
414414
}
415415

416416
/// Returns a message part by position
417-
pub fn part(&self, pos: usize) -> Option<&MessagePart> {
417+
pub fn part(&self, pos: usize) -> Option<&MessagePart<'x>> {
418418
self.parts.get(pos)
419419
}
420420

421421
/// Returns an inline HTML body part by position
422-
pub fn html_part(&self, pos: usize) -> Option<&MessagePart> {
422+
pub fn html_part(&self, pos: usize) -> Option<&MessagePart<'x>> {
423423
self.parts.get(*self.html_body.get(pos)?)
424424
}
425425

426426
/// Returns an inline text body part by position
427-
pub fn text_part(&self, pos: usize) -> Option<&MessagePart> {
427+
pub fn text_part(&self, pos: usize) -> Option<&MessagePart<'x>> {
428428
self.parts.get(*self.text_body.get(pos)?)
429429
}
430430

src/decoders/encoded_word.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<'x> MessageStream<'x> {
2626

2727
let mut charset_start = 0;
2828
let mut charset_end = 0;
29-
let mut decode_fnc: Option<DecodeWordFnc> = None;
29+
let mut decode_fnc: Option<DecodeWordFnc<'_>> = None;
3030

3131
while let Some(ch) = self.next() {
3232
match state {

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(rust_2018_idioms)]
12
/*
23
* Copyright Stalwart Labs Ltd. See the COPYING
34
* file at the top-level directory of this distribution.
@@ -619,15 +620,15 @@ pub trait MimeHeaders<'x> {
619620
/// Returns the Content-Description field
620621
fn content_description(&self) -> Option<&str>;
621622
/// Returns the Content-Disposition field
622-
fn content_disposition(&self) -> Option<&ContentType>;
623+
fn content_disposition(&self) -> Option<&ContentType<'_>>;
623624
/// Returns the Content-ID field
624625
fn content_id(&self) -> Option<&str>;
625626
/// Returns the Content-Encoding field
626627
fn content_transfer_encoding(&self) -> Option<&str>;
627628
/// Returns the Content-Type field
628-
fn content_type(&self) -> Option<&ContentType>;
629+
fn content_type(&self) -> Option<&ContentType<'_>>;
629630
/// Returns the Content-Language field
630-
fn content_language(&self) -> &HeaderValue;
631+
fn content_language(&self) -> &HeaderValue<'_>;
631632
/// Returns the Content-Location field
632633
fn content_location(&self) -> Option<&str>;
633634
/// Returns the attachment name, if any.

src/mailbox/maildir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl FolderIterator<'_> {
5656
pub fn new(
5757
path: impl Into<PathBuf>,
5858
sub_folder_prefix: Option<&str>,
59-
) -> io::Result<FolderIterator> {
59+
) -> io::Result<FolderIterator<'_>> {
6060
let path = path.into();
6161

6262
Ok(FolderIterator {

src/parsers/fields/content_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'x> ContentTypeParser<'x> {
223223
self.reset_parser();
224224
}
225225

226-
fn add_attr_position(&mut self, stream: &MessageStream) -> bool {
226+
fn add_attr_position(&mut self, stream: &MessageStream<'_>) -> bool {
227227
if self.token_start > 0 {
228228
self.attr_position =
229229
String::from_utf8_lossy(&stream.data[self.token_start - 1..self.token_end])

0 commit comments

Comments
 (0)