Created
February 25, 2014 13:09
-
-
Save pzol/9208438 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct LowerChars<'a> { | |
chars: std::str::Chars<'a> | |
} | |
fn lower<'a>(s: &'a str) -> LowerChars<'a> { | |
LowerChars { chars: s.chars() } | |
} | |
impl<'a> Iterator<char> for LowerChars<'a> { | |
fn next(&mut self) -> Option<char> { | |
self.chars.next().map(|c| c.to_lowercase()) | |
} | |
} | |
#[test] | |
fn test_to_uppercase(){ | |
let sl = "foobär"; | |
let su = "FOOBÄR"; | |
let mut z = lower(sl).zip(lower(su)); | |
assert!(z.all(|(x, y)| x == y )); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment