Skip to main content

eml_codec/part/
discrete.rs

1#[cfg(feature = "arbitrary")]
2use arbitrary::Arbitrary;
3use bounded_static::ToStatic;
4use std::borrow::Cow;
5use std::fmt;
6
7use crate::mime;
8use crate::raw_input::RawInput;
9#[cfg(feature = "arbitrary")]
10use crate::{arbitrary_utils::arbitrary_part_body, fuzz_eq::FuzzEq};
11
12#[derive(Clone, PartialEq, ToStatic)]
13#[cfg_attr(feature = "arbitrary", derive(FuzzEq))]
14pub struct Text<'a> {
15    pub mime: mime::MIME<'a, mime::r#type::Text<'a>>,
16    #[cfg_attr(feature = "arbitrary", fuzz_eq(use_eq))]
17    pub body: Cow<'a, [u8]>,
18    pub raw_body: RawInput<'a>,
19}
20
21impl<'a> fmt::Debug for Text<'a> {
22    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
23        fmt.debug_struct("part::Text")
24            .field("mime", &self.mime)
25            .field("body", &String::from_utf8_lossy(&self.body))
26            .field("raw_body", &self.raw_body)
27            .finish()
28    }
29}
30
31#[cfg(feature = "arbitrary")]
32impl<'a> Arbitrary<'a> for Text<'a> {
33    fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
34        Ok(Self {
35            mime: u.arbitrary()?,
36            body: arbitrary_part_body(u)?.into(),
37            raw_body: RawInput::none(),
38        })
39    }
40}
41
42#[derive(Clone, PartialEq, ToStatic)]
43#[cfg_attr(feature = "arbitrary", derive(FuzzEq))]
44pub struct Binary<'a> {
45    pub mime: mime::MIME<'a, mime::r#type::Binary<'a>>,
46    #[cfg_attr(feature = "arbitrary", fuzz_eq(use_eq))]
47    pub body: Cow<'a, [u8]>,
48    pub raw_body: RawInput<'a>,
49}
50
51impl<'a> fmt::Debug for Binary<'a> {
52    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
53        fmt.debug_struct("part::Binary")
54            .field("mime", &self.mime)
55            .field("body", &String::from_utf8_lossy(&self.body))
56            .field("raw_body", &self.raw_body)
57            .finish()
58    }
59}
60
61#[cfg(feature = "arbitrary")]
62impl<'a> Arbitrary<'a> for Binary<'a> {
63    fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
64        Ok(Self {
65            mime: u.arbitrary()?,
66            body: arbitrary_part_body(u)?.into(),
67            raw_body: RawInput::none(),
68        })
69    }
70}