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
parent
8ddd673dd8
commit
0270db0123
|
@ -222,8 +222,9 @@ impl std::fmt::Display for MultipartType {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&[u8]> for MultipartType {
|
||||
fn from(val: &[u8]) -> Self {
|
||||
impl<B: AsRef<[u8]>> From<B> 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<B: AsRef<[u8]>> From<B> 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<B: AsRef<[u8]>> From<B> 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()
|
||||
|
|
|
@ -74,8 +74,9 @@ macro_rules! uuid_hash_type {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&[u8]> for $n {
|
||||
fn from(val: &[u8]) -> Self {
|
||||
impl<B: AsRef<[u8]>> From<B> for $n {
|
||||
fn from(val: B) -> Self {
|
||||
let val = val.as_ref();
|
||||
$n(Uuid::new_v5(&Uuid::NAMESPACE_URL, val))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue