fix: remove unwraps()

update_containers use an if let Some() instead of an unwrtap().to_owned()
This commit is contained in:
Jack Wills
2022-05-30 01:30:24 +00:00
parent 846fb60131
commit d68285a233
+5 -3
View File
@@ -310,7 +310,7 @@ impl AppData {
} }
for i in containers.iter() { for i in containers.iter() {
let id = i.id.as_ref().unwrap().to_owned(); if let Some(id) = i.id.as_ref() {
let mut name = i let mut name = i
.names .names
.as_ref() .as_ref()
@@ -332,7 +332,7 @@ impl AppData {
.trim() .trim()
.to_owned(); .to_owned();
let image = i.image.as_ref().unwrap_or(&"".to_owned()).trim().to_owned(); let image = i.image.as_ref().unwrap_or(&"".to_owned()).trim().to_owned();
if let Some(current_container) = self.get_container_by_id(&id) { if let Some(current_container) = self.get_container_by_id(id) {
if current_container.name != name { if current_container.name != name {
current_container.name = name current_container.name = name
}; };
@@ -355,12 +355,14 @@ impl AppData {
current_container.image = image current_container.image = image
}; };
} else { } else {
let mut container = ContainerItem::new(id, status, image, state, name); let mut container =
ContainerItem::new(id.to_owned(), status, image, state, name);
container.logs.end(); container.logs.end();
self.containers.items.push(container); self.containers.items.push(container);
} }
} }
} }
}
/// update logs of a given container, based on index not id /// update logs of a given container, based on index not id
pub fn update_log_by_index(&mut self, output: Vec<String>, index: usize) { pub fn update_log_by_index(&mut self, output: Vec<String>, index: usize) {