multipart_rs/
multipart_type.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::str::FromStr;

use crate::error::MultipartError;

#[derive(Debug, PartialEq)]
pub enum MultipartType {
    // Form-Data - RFC 2388
    FormData,

    // Mixed - RFC 2046
    Mixed,

    // Alternative - RFC 2046
    Alternative,

    // Digest - RFC 2046
    Digest,

    // Related - RFC 2387
    Related,
}

impl FromStr for MultipartType {
    type Err = MultipartError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "form-data" => Ok(MultipartType::FormData),
            "mixed" => Ok(MultipartType::Mixed),
            "alternative" => Ok(MultipartType::Alternative),
            "digest" => Ok(MultipartType::Digest),
            "related" => Ok(MultipartType::Related),
            _ => Err(MultipartError::InvalidMultipartType),
        }
    }
}