Make StatusMessage::from accept Strings and slices

This commit is contained in:
Timothy Warren 2021-03-10 14:51:54 -05:00
parent 31e5fd6633
commit 2607f8bd63

View File

@ -23,10 +23,10 @@ struct StatusMessage {
}
impl StatusMessage {
fn from(message: String) -> Self {
fn from<S: Into<String>>(message: S) -> Self {
Self {
time: Instant::now(),
text: message,
text: message.into(),
}
}
}
@ -147,9 +147,9 @@ impl Editor {
Key::Ctrl('q') => self.should_quit = true,
Key::Ctrl('s') => {
if self.document.save().is_ok() {
self.status_message = StatusMessage::from("File saved successfully.".to_string());
self.status_message = StatusMessage::from("File saved successfully.");
} else {
self.status_message = StatusMessage::from("Error writing file!".to_string());
self.status_message = StatusMessage::from("Error writing file!");
}
}
Key::Char(c) => {