From 33c691bbd1043635a1f4c3be8fe1a097c5b4e0b7 Mon Sep 17 00:00:00 2001 From: akolybelnikov Date: Wed, 24 Jul 2019 18:36:34 +0200 Subject: [PATCH 1/2] Alternative solution to c01p03. --- src/bin/c01p03_alt.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/bin/c01p03_alt.rs diff --git a/src/bin/c01p03_alt.rs b/src/bin/c01p03_alt.rs new file mode 100644 index 0000000..39229bb --- /dev/null +++ b/src/bin/c01p03_alt.rs @@ -0,0 +1,17 @@ +fn urlify(url: &str) -> String { + url.trim().replace(" ", "%20") +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_urlify() { + assert_eq!(urlify(&"Mr John Smith "), "Mr%20John%20Smith"); + } +} + +fn main() { + urlify(&"Mr John Smith "); +} From 03c60b8d250089abf356a356058a2f0531615cf3 Mon Sep 17 00:00:00 2001 From: Andrey Kolybelnikov Date: Thu, 25 Jul 2019 10:42:33 +0200 Subject: [PATCH 2/2] Moved the alternative solution to the file with the original one. --- src/bin/c01p03.rs | 10 ++++++++++ src/bin/c01p03_alt.rs | 17 ----------------- 2 files changed, 10 insertions(+), 17 deletions(-) delete mode 100644 src/bin/c01p03_alt.rs diff --git a/src/bin/c01p03.rs b/src/bin/c01p03.rs index 1249cf5..caeece8 100644 --- a/src/bin/c01p03.rs +++ b/src/bin/c01p03.rs @@ -10,6 +10,11 @@ fn urlify(url: &'static str) -> String { }) } +// Alternative solution with shorter syntax +fn urlify_2(url: &str) -> String { + url.trim().replace(" ", "%20") +} + #[cfg(test)] mod tests { use super::*; @@ -18,8 +23,13 @@ mod tests { fn test_urlify() { assert_eq!(urlify(&"Mr John Smith "), "Mr%20John%20Smith"); } + #[test] + fn test_urlify_2() { + assert_eq!(urlify_2(&"Mr John Smith "), "Mr%20John%20Smith"); + } } fn main() { urlify(&"Mr John Smith "); + urlify_2(&"Mr John Smith "); } diff --git a/src/bin/c01p03_alt.rs b/src/bin/c01p03_alt.rs deleted file mode 100644 index 39229bb..0000000 --- a/src/bin/c01p03_alt.rs +++ /dev/null @@ -1,17 +0,0 @@ -fn urlify(url: &str) -> String { - url.trim().replace(" ", "%20") -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_urlify() { - assert_eq!(urlify(&"Mr John Smith "), "Mr%20John%20Smith"); - } -} - -fn main() { - urlify(&"Mr John Smith "); -}