-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
status_report.rs
47 lines (40 loc) · 1.05 KB
/
status_report.rs
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
//! Struct to store and update status messages
use std::collections::VecDeque;
/// Struct to store and update status messages
pub struct StatusReport {
status: VecDeque<String>,
}
impl StatusReport {
/// Create a new ``StatusReport`` instance with a blank status
pub fn new() -> Self {
Self {
status: VecDeque::new(),
}
}
/// Update the status
pub fn update_status(&mut self, status: &str) {
let status = format!("\n{}", status.to_owned());
self.status.push_back(status);
if self.status.len() > 5 {
for _ in 0..(self.status.len() - 5) {
self.status.pop_front();
}
}
}
/// Get current status
pub fn status(&self) -> String {
self.status
.iter()
.map(std::string::ToString::to_string)
.collect::<String>()
}
/// Reset status
pub fn clear_status(&mut self) {
self.status.clear();
}
}
impl Default for StatusReport {
fn default() -> Self {
Self::new()
}
}