#How to optimize this code and more readable with struct or enum?
7 messages ยท Page 1 of 1 (latest)
Why not just have a three-value enum and a method that converts it into a string?
Alternatively, have a value of type [(MyEnum, &str); 3]
Actually, what do you mean by "optimize"?
enum Command {
Echo,
Quit,
Help,
}
impl Command {
fn as_shortcut_text(&self) -> &'static str {
match self {
Self::Echo => "echo",
Self::Quit => ":q",
Self::Help => "?",
}
}
}
It's to clean up the code
In programming, "optimize" actually means, "make the code run faster". I'd suggest avoiding using that word with that meaning in the future ๐
Oh sorry ๐