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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use std::path::PathBuf;
use std::sync::Arc;

use teo_teon::Value;

#[derive(Clone)]
pub struct Body {
    pub inner: Arc<BodyInner>
}

impl Body {

    pub fn empty() -> Self {
        Self {
            inner: Arc::new(BodyInner::Empty)
        }
    }

    pub fn string(content: String) -> Self {
        Self {
            inner: Arc::new(BodyInner::String(content))
        }
    }

    pub fn file(content: PathBuf) -> Self {
        Self {
            inner: Arc::new(BodyInner::File(content))
        }
    }

    pub fn teon(content: Value) -> Self {
        Self {
            inner: Arc::new(BodyInner::Teon(content))
        }
    }

    pub fn is_empty(&self) -> bool {
        match self.inner.as_ref() {
            BodyInner::Empty => true,
            _ => false,
        }
    }

    pub fn is_file(&self) -> bool {
        match self.inner.as_ref() {
            BodyInner::File(_) => true,
            _ => false,
        }
    }

    pub fn as_file(&self) -> Option<&PathBuf> {
        match self.inner.as_ref() {
            BodyInner::File(v) => Some(v),
            _ => None,
        }
    }

    pub fn is_text(&self) -> bool {
        match self.inner.as_ref() {
            BodyInner::String(_) => true,
            _ => false,
        }
    }

    pub fn as_text(&self) -> Option<&String> {
        match self.inner.as_ref() {
            BodyInner::String(v) => Some(v),
            _ => None,
        }
    }

    pub fn is_teon(&self) -> bool {
        match self.inner.as_ref() {
            BodyInner::Teon(_) => true,
            _ => false,
        }
    }

    pub fn as_teon(&self) -> Option<&Value> {
        match self.inner.as_ref() {
            BodyInner::Teon(v) => Some(v),
            _ => None,
        }
    }
}

pub enum BodyInner {
    Empty,
    String(String),
    File(PathBuf),
    Teon(Value),
}