From 0a1d8009bf678d8ea457f124c4e3adf6b6addf75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Sun, 12 Jan 2020 20:39:56 -0700 Subject: Simplify the Rust code --- src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9252c56..2a75e85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,9 +30,7 @@ fn build() { for file in &files { println!("File: {}", file.to_str().unwrap()); if !file.to_str().unwrap().ends_with("main.f90") { - let s1:String = files2.to_string(); - let s2:String = file.to_str().unwrap().to_string(); - files2 = s1 + " " + &s2; + files2 = files2 + " " + file.to_str().unwrap(); } } println!("Files: {:?}", files); -- cgit v1.2.3 From e1e4e9d459378af32e5abddd89be6b544ad0eb83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Sun, 12 Jan 2020 21:52:35 -0700 Subject: Use Vec --- src/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2a75e85..8fb71c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,8 +6,8 @@ struct Cli { command: String, } -fn collect_source_files() -> Vec { - let mut files: Vec = Vec::new(); +fn collect_source_files() -> Vec { + let mut files: Vec = Vec::new(); for entry in std::fs::read_dir(".").unwrap() { let entry = entry.unwrap(); let path = entry.path(); @@ -17,7 +17,7 @@ fn collect_source_files() -> Vec { Some(ext) => ext.to_str().unwrap(), }; if ext == "f90" { - files.push(path); + files.push(path.to_str().unwrap().to_string()); } } } @@ -28,9 +28,9 @@ fn build() { let files = collect_source_files(); let mut files2: String = String::new(); for file in &files { - println!("File: {}", file.to_str().unwrap()); - if !file.to_str().unwrap().ends_with("main.f90") { - files2 = files2 + " " + file.to_str().unwrap(); + println!("File: {}", file); + if !file.ends_with("main.f90") { + files2 = files2 + " " + file; } } println!("Files: {:?}", files); -- cgit v1.2.3