From 0270db0123eeb5abb41e53d07d308f1bd541f2a6 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 1 Jan 2024 15:16:47 +0200 Subject: [PATCH] melib: From<&[u8]> -> From> This change allows byte literals to be used with the from trait method. Signed-off-by: Manos Pitsidianakis --- melib/src/email/attachment_types.rs | 15 +++++++++------ melib/src/thread.rs | 5 +++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/melib/src/email/attachment_types.rs b/melib/src/email/attachment_types.rs index 0d3c80f8..6bb963e1 100644 --- a/melib/src/email/attachment_types.rs +++ b/melib/src/email/attachment_types.rs @@ -222,8 +222,9 @@ impl std::fmt::Display for MultipartType { } } -impl From<&[u8]> for MultipartType { - fn from(val: &[u8]) -> Self { +impl> From for MultipartType { + fn from(val: B) -> Self { + let val = val.as_ref(); if val.eq_ignore_ascii_case(b"mixed") { Self::Mixed } else if val.eq_ignore_ascii_case(b"alternative") { @@ -488,8 +489,9 @@ impl std::fmt::Display for ContentTransferEncoding { } } } -impl From<&[u8]> for ContentTransferEncoding { - fn from(val: &[u8]) -> Self { +impl> From for ContentTransferEncoding { + fn from(val: B) -> Self { + let val = val.as_ref(); if val.eq_ignore_ascii_case(b"base64") { Self::Base64 } else if val.eq_ignore_ascii_case(b"7bit") { @@ -542,8 +544,9 @@ impl std::fmt::Display for ContentDispositionKind { } } } -impl From<&[u8]> for ContentDisposition { - fn from(val: &[u8]) -> Self { +impl> From for ContentDisposition { + fn from(val: B) -> Self { + let val = val.as_ref(); crate::email::parser::attachments::content_disposition(val) .map(|(_, v)| v) .unwrap_or_default() diff --git a/melib/src/thread.rs b/melib/src/thread.rs index 71be9e08..00af2cc7 100644 --- a/melib/src/thread.rs +++ b/melib/src/thread.rs @@ -74,8 +74,9 @@ macro_rules! uuid_hash_type { } } - impl From<&[u8]> for $n { - fn from(val: &[u8]) -> Self { + impl> From for $n { + fn from(val: B) -> Self { + let val = val.as_ref(); $n(Uuid::new_v5(&Uuid::NAMESPACE_URL, val)) } }