aboutsummaryrefslogtreecommitdiff
path: root/src/message.rs
blob: d1032cf1023db49d6adc95bd0fec7a7553ca49ac (plain)
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
#[derive(Debug)]
pub struct Message {
    pub text: String,
    pub kind: MessageKind,
}

impl Message {
    pub fn new() -> Self {
        Self {
            text: String::new(),
            kind: MessageKind::Info,
        }
    }
    pub fn kind(mut self, kind: MessageKind) -> Self {
        self.kind = kind;
        self
    }
    pub fn text<S: AsRef<str>>(mut self, text: S) -> Self {
        self.text = text.as_ref().into();
        self
    }
}

#[derive(Debug, Copy, Clone)]
pub enum MessageKind {
    Error,
    Info,
    Hint,
    LispResult,
}

impl<T> From<T> for Message
where
    T: AsRef<str>,
{
    fn from(item: T) -> Self {
        return Message {
            text: item.as_ref().into(),
            kind: MessageKind::Info,
        };
    }
}