refactor: return &[T] instead of &Vec<T>

This commit is contained in:
Jack Wills
2024-02-05 22:30:30 +00:00
parent 0314eac9df
commit 76cd08ab2f
+10 -9
View File
@@ -212,7 +212,7 @@ impl AppData {
} }
/// Get all the ContainerItems /// Get all the ContainerItems
pub const fn get_container_items(&self) -> &Vec<ContainerItem> { pub fn get_container_items(&self) -> &[ContainerItem] {
&self.containers.items &self.containers.items
} }
@@ -383,6 +383,7 @@ impl AppData {
} }
/// Get mutable Option of the currently selected container DockerControls items /// Get mutable Option of the currently selected container DockerControls items
/// TODO command or control, need a uniform name acorss the application
pub fn get_control_items(&mut self) -> Option<&mut Vec<DockerControls>> { pub fn get_control_items(&mut self) -> Option<&mut Vec<DockerControls>> {
self.get_mut_selected_container() self.get_mut_selected_container()
.map(|i| &mut i.docker_controls.items) .map(|i| &mut i.docker_controls.items)
@@ -1229,7 +1230,7 @@ mod tests {
} }
#[test] #[test]
// Get the currently selected container /// Get the currently selected container
fn test_app_data_get_selected_container() { fn test_app_data_get_selected_container() {
let (_ids, mut containers) = gen_containers(); let (_ids, mut containers) = gen_containers();
let mut app_data = gen_appdata(&containers); let mut app_data = gen_appdata(&containers);
@@ -1249,7 +1250,7 @@ mod tests {
} }
#[test] #[test]
// Get mut container by id /// Get mut container by id
fn test_app_data_get_container_by_id() { fn test_app_data_get_container_by_id() {
let (_ids, mut containers) = gen_containers(); let (_ids, mut containers) = gen_containers();
let mut app_data = gen_appdata(&containers); let mut app_data = gen_appdata(&containers);
@@ -1259,7 +1260,7 @@ mod tests {
} }
#[test] #[test]
// Get just the containers name by id /// Get just the containers name by id
fn test_app_data_get_container_name_by_id() { fn test_app_data_get_container_name_by_id() {
let (_ids, containers) = gen_containers(); let (_ids, containers) = gen_containers();
let mut app_data = gen_appdata(&containers); let mut app_data = gen_appdata(&containers);
@@ -1269,7 +1270,7 @@ mod tests {
} }
#[test] #[test]
// Get the id of the currently selected container /// Get the id of the currently selected container
fn test_app_data_get_selected_container_id() { fn test_app_data_get_selected_container_id() {
let (_ids, containers) = gen_containers(); let (_ids, containers) = gen_containers();
let mut app_data = gen_appdata(&containers); let mut app_data = gen_appdata(&containers);
@@ -1832,15 +1833,15 @@ mod tests {
fn test_app_data_update_containers() { fn test_app_data_update_containers() {
let (_ids, containers) = gen_containers(); let (_ids, containers) = gen_containers();
let mut app_data = gen_appdata(&containers); let mut app_data = gen_appdata(&containers);
let result_pre = app_data.get_container_items().clone(); let result_pre = app_data.get_container_items().to_owned();
let mut input = vec![ let mut input = [
gen_container_summary(1, "paused"), gen_container_summary(1, "paused"),
gen_container_summary(2, "dead"), gen_container_summary(2, "dead"),
]; ];
app_data.update_containers(&mut input); app_data.update_containers(&mut input);
let result_post = app_data.get_container_items(); let result_post = app_data.get_container_items().to_owned();
assert_ne!(&result_pre, result_post); assert_ne!(result_pre, result_post);
assert_eq!(result_post[0].state, State::Paused); assert_eq!(result_post[0].state, State::Paused);
assert_eq!(result_post[1].state, State::Dead); assert_eq!(result_post[1].state, State::Dead);
} }