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 "); }