email_encoding/body/
mod.rs

1//! Email body encoding algorithms.
2
3use core::ops::Deref;
4
5pub mod base64;
6mod chooser;
7
8/// A possible email `Content-Transfer-Encoding`
9#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
10pub enum Encoding {
11    /// 7bit (US-ASCII)
12    SevenBit,
13    /// 8bit (UTF-8)
14    EightBit,
15    /// [Quoted Printable](https://docs.rs/quoted_printable/0.4.5/quoted_printable/fn.encode_to_str.html)
16    QuotedPrintable,
17    /// [Base64](self::base64::encode)
18    Base64,
19}
20
21/// A borrowed `str` or `[u8]`
22#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
23pub enum StrOrBytes<'a> {
24    /// `str` variant
25    Str(&'a str),
26    /// `[u8]` variant
27    Bytes(&'a [u8]),
28}
29
30impl<'a> From<&'a str> for StrOrBytes<'a> {
31    fn from(s: &'a str) -> Self {
32        Self::Str(s)
33    }
34}
35
36impl<'a> From<&'a [u8]> for StrOrBytes<'a> {
37    fn from(s: &'a [u8]) -> Self {
38        Self::Bytes(s)
39    }
40}
41
42impl<'a, const N: usize> From<&'a [u8; N]> for StrOrBytes<'a> {
43    fn from(s: &'a [u8; N]) -> Self {
44        Self::Bytes(s)
45    }
46}
47
48impl Deref for StrOrBytes<'_> {
49    type Target = [u8];
50
51    fn deref(&self) -> &Self::Target {
52        match self {
53            Self::Str(s) => s.as_bytes(),
54            Self::Bytes(b) => b,
55        }
56    }
57}