src/global/message.rs

db597a03bc7a1786d5261e8a55628da30193c775
youtube-tui/src/global/message.rs history · blame · raw

24 lines · 548 bytes

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