melib: From<&[u8]> -> From<B: AsRef<[u8]>>

This change allows byte literals to be used with the from trait method.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/338/head
Manos Pitsidianakis 5 months ago
parent 8ddd673dd8
commit 0270db0123
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -222,8 +222,9 @@ impl std::fmt::Display for MultipartType {
} }
} }
impl From<&[u8]> for MultipartType { impl<B: AsRef<[u8]>> From<B> for MultipartType {
fn from(val: &[u8]) -> Self { fn from(val: B) -> Self {
let val = val.as_ref();
if val.eq_ignore_ascii_case(b"mixed") { if val.eq_ignore_ascii_case(b"mixed") {
Self::Mixed Self::Mixed
} else if val.eq_ignore_ascii_case(b"alternative") { } else if val.eq_ignore_ascii_case(b"alternative") {
@ -488,8 +489,9 @@ impl std::fmt::Display for ContentTransferEncoding {
} }
} }
} }
impl From<&[u8]> for ContentTransferEncoding { impl<B: AsRef<[u8]>> From<B> for ContentTransferEncoding {
fn from(val: &[u8]) -> Self { fn from(val: B) -> Self {
let val = val.as_ref();
if val.eq_ignore_ascii_case(b"base64") { if val.eq_ignore_ascii_case(b"base64") {
Self::Base64 Self::Base64
} else if val.eq_ignore_ascii_case(b"7bit") { } else if val.eq_ignore_ascii_case(b"7bit") {
@ -542,8 +544,9 @@ impl std::fmt::Display for ContentDispositionKind {
} }
} }
} }
impl From<&[u8]> for ContentDisposition { impl<B: AsRef<[u8]>> From<B> for ContentDisposition {
fn from(val: &[u8]) -> Self { fn from(val: B) -> Self {
let val = val.as_ref();
crate::email::parser::attachments::content_disposition(val) crate::email::parser::attachments::content_disposition(val)
.map(|(_, v)| v) .map(|(_, v)| v)
.unwrap_or_default() .unwrap_or_default()

@ -74,8 +74,9 @@ macro_rules! uuid_hash_type {
} }
} }
impl From<&[u8]> for $n { impl<B: AsRef<[u8]>> From<B> for $n {
fn from(val: &[u8]) -> Self { fn from(val: B) -> Self {
let val = val.as_ref();
$n(Uuid::new_v5(&Uuid::NAMESPACE_URL, val)) $n(Uuid::new_v5(&Uuid::NAMESPACE_URL, val))
} }
} }

Loading…
Cancel
Save