src/global/structs/message.rs

84c4617332578aaf4e9ee68a0a2d7d6258e48243
youtube-tui/src/global/structs/message.rs history · blame · raw

32 lines · 711 bytes

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