From 06e60dce14069cedab74d8a6924dc599052b3d41 Mon Sep 17 00:00:00 2001 From: Adam Cooper Date: Tue, 15 Feb 2022 09:31:15 -0500 Subject: [PATCH] [wip] Change of approach: moving the Multistatus Move the Multistatus value from the main function into the traverse function, as it will not be used in the main function afterwards. In the traverse function, the struct is now borrowed as mutable, which fixes the append function, but we'll probably need to use references in all the match arms. --- src/main.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index a275170..ec12590 100644 --- a/src/main.rs +++ b/src/main.rs @@ -126,7 +126,7 @@ async fn get_folder_contents(url_tail: &String) -> Result match prop.get_etag { Some(etag) => { @@ -149,14 +149,12 @@ async fn traverse(result: &Multistatus) { while !result.response.is_empty() { match &result.response[current_index].propstat[0].prop { Some(prop) => { - match &prop.get_etag { + match prop.get_etag { Some(etag) => { // If result.response[current_index] has not been visited - if !visited_items.contains_key(etag) { + if !visited_items.contains_key(&etag) { // If item is a collection - // TODO(amcooper): Again, replace unwrap with the match implementation, - // or find another way to handle these structures. - match &prop.resource_type { + match prop.resource_type { Some(resource_type) => { if !resource_type.collection.is_empty() { // Get the contents XML @@ -169,7 +167,7 @@ async fn traverse(result: &Multistatus) { // Parse the contents XML into Multistatus let mut new_result: Multistatus = from_str(&String::from(folder_contents)).unwrap(); // Append the NextcloudResponse vector to result.response - result.response.append(&new_result.response); + result.response.append(&mut new_result.response); } } _ => current_index += 1, @@ -228,6 +226,6 @@ async fn main() -> std::io::Result<()> { let mut result: Multistatus = from_str(&folder_contents).unwrap(); println!("{:?}", result); - traverse(&result); + traverse(result); Ok(()) }