Skip to content

Commit 60fe70d

Browse files
authored
fix: express custom trait with stdlib traits (#101)
1 parent 209778f commit 60fe70d

File tree

1 file changed

+4
-38
lines changed

1 file changed

+4
-38
lines changed

src/parsers/message.rs

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,17 @@ impl MessageParser {
108108
/// This function never panics, a best-effort is made to parse the message and
109109
/// if no headers are found None is returned.
110110
///
111-
pub fn parse<'x>(&self, raw_message: impl IntoByteSlice<'x>) -> Option<Message<'x>> {
112-
self.parse_(raw_message.into_byte_slice(), MAX_NESTED_ENCODED, false)
111+
pub fn parse<'x>(&self, raw_message: &'x (impl AsRef<[u8]> + ?Sized)) -> Option<Message<'x>> {
112+
self.parse_(raw_message.as_ref(), MAX_NESTED_ENCODED, false)
113113
}
114114

115115
/// Parses a byte slice containing the RFC5322 raw message and returns a
116116
/// `Message` struct containing only the headers.
117117
pub fn parse_headers<'x>(
118118
&self,
119-
raw_message: impl IntoByteSlice<'x> + 'x,
119+
raw_message: &'x (impl AsRef<[u8]> + ?Sized),
120120
) -> Option<Message<'x>> {
121-
self.parse_(raw_message.into_byte_slice(), MAX_NESTED_ENCODED, true)
121+
self.parse_(raw_message.as_ref(), MAX_NESTED_ENCODED, true)
122122
}
123123

124124
fn parse_<'x>(
@@ -549,40 +549,6 @@ impl<'x> Message<'x> {
549549
}
550550
}
551551

552-
pub trait IntoByteSlice<'x> {
553-
fn into_byte_slice(self) -> &'x [u8];
554-
}
555-
556-
impl<'x> IntoByteSlice<'x> for &'x [u8] {
557-
fn into_byte_slice(self) -> &'x [u8] {
558-
self
559-
}
560-
}
561-
562-
impl<'x, const N: usize> IntoByteSlice<'x> for &'x [u8; N] {
563-
fn into_byte_slice(self) -> &'x [u8] {
564-
self
565-
}
566-
}
567-
568-
impl<'x> IntoByteSlice<'x> for &'x str {
569-
fn into_byte_slice(self) -> &'x [u8] {
570-
self.as_bytes()
571-
}
572-
}
573-
574-
impl<'x> IntoByteSlice<'x> for &'x String {
575-
fn into_byte_slice(self) -> &'x [u8] {
576-
self.as_bytes()
577-
}
578-
}
579-
580-
impl<'x> IntoByteSlice<'x> for &'x Vec<u8> {
581-
fn into_byte_slice(self) -> &'x [u8] {
582-
self
583-
}
584-
}
585-
586552
#[cfg(test)]
587553
mod tests {
588554
use std::{fs, path::PathBuf};

0 commit comments

Comments
 (0)