diff --git a/src/app_data/container_state.rs b/src/app_data/container_state.rs index 974356b..a54608d 100644 --- a/src/app_data/container_state.rs +++ b/src/app_data/container_state.rs @@ -18,18 +18,6 @@ const ONE_GB: f64 = ONE_MB * 1000.0; #[derive(Debug, Clone, Eq, Hash, PartialEq)] pub struct ContainerId(String); -impl From for ContainerId { - fn from(x: String) -> Self { - Self(x) - } -} - -impl From<&String> for ContainerId { - fn from(x: &String) -> Self { - Self(x.clone()) - } -} - impl From<&str> for ContainerId { fn from(x: &str) -> Self { Self(x.to_owned()) @@ -156,20 +144,6 @@ impl State { } } -impl From for State { - fn from(input: String) -> Self { - match input.as_ref() { - "dead" => Self::Dead, - "exited" => Self::Exited, - "paused" => Self::Paused, - "removing" => Self::Removing, - "restarting" => Self::Restarting, - "running" => Self::Running, - _ => Self::Unknown, - } - } -} - impl From<&str> for State { fn from(input: &str) -> Self { match input { diff --git a/src/app_data/mod.rs b/src/app_data/mod.rs index 0d5db00..6abeacc 100644 --- a/src/app_data/mod.rs +++ b/src/app_data/mod.rs @@ -426,7 +426,7 @@ impl AppData { /// So can display nicely and evenly pub fn get_width(&self) -> Columns { let mut columns = Columns::new(); - let count = |x: &String| u8::try_from(x.chars().count()).unwrap_or(12); + let count = |x: &str| u8::try_from(x.chars().count()).unwrap_or(12); // Should probably find a refactor here somewhere for container in &self.containers.items { @@ -552,9 +552,6 @@ impl AppData { } } - // Trim a &String and return String - let trim_owned = |x: &String| x.trim().to_owned(); - for i in all_containers { if let Some(id) = i.id.as_ref() { let name = i.names.as_mut().map_or(String::new(), |names| { @@ -571,15 +568,15 @@ impl AppData { .as_ref() .map_or(false, |i| i.starts_with(ENTRY_POINT)); - let state = State::from(i.state.as_ref().map_or("dead".to_owned(), trim_owned)); - let status = i.status.as_ref().map_or(String::new(), trim_owned); + let state = State::from(i.state.as_ref().map_or("dead", |z| z)); + let status = i.status.as_ref().map_or(String::new(), std::clone::Clone::clone); let image = i .image .as_ref() .map_or(String::new(), std::clone::Clone::clone); - let id = ContainerId::from(id); + let id = ContainerId::from(id.as_str()); let created = i .created diff --git a/src/docker_data/mod.rs b/src/docker_data/mod.rs index 51d5437..1540597 100644 --- a/src/docker_data/mod.rs +++ b/src/docker_data/mod.rs @@ -216,7 +216,7 @@ impl DockerData { ( i.state == Some("running".to_owned()) || i.state == Some("restarting".to_owned()), - ContainerId::from(id), + ContainerId::from(id.as_str()), ) }) })