src/global/structs/message.rs

25 lines · 560 bytes

 1use typemap::Key;
 2
 3/// Messages in the message bar
 4// is stored in `data.global`
 5#[derive(Clone)]
 6pub enum Message {
 7    Message(String),
 8    Error(String),
 9    Success(String),
10    None,
11}
12
13impl Key for Message {
14    type Value = Self;
15}
16
17impl Message {
18    // to_string is used by the message bar to convert Message to string
19    pub fn to_string(&self, default: &str) -> String {
20        match self {
21            Self::Message(msg) | Self::Error(msg) | Self::Success(msg) => msg.to_string(),
22            Self::None => default.to_string(),
23        }
24    }
25}