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
#[derive(Debug)] #[doc = "Represents a command that is selectable in the menu"] pub struct Command { key: String, display: String, command: String, } impl Command { #[doc = "Creates a new instance of Command"] pub fn new<K, D, C>(key: K, display: D, command: C) -> Command where K: Into<String>, D: Into<String>, C: Into<String>, { Command { key: key.into(), display: display.into(), command: command.into(), } } #[doc = "Returns the key"] pub fn key(&self) -> &str { &self.key } #[doc = "Returns the display string"] pub fn display(&self) -> &str { &self.display } #[doc = "Returns the command"] pub fn command(&self) -> &str { &self.command } } impl Into<String> for Command { #[doc = "Returns a string representation"] fn into(self) -> String { self.display.clone() } } impl From<String> for Command { #[doc = "Creates a Command where key, display, and command are equal to arg"] fn from(arg: String) -> Command { Command::new(arg.clone(), arg.clone(), arg) } } impl Clone for Command { fn clone(&self) -> Self { Command { key: self.key.clone(), display: self.display.clone(), command: self.command.clone(), } } }