Skip to content

Instantly share code, notes, and snippets.

@pzol
Created February 25, 2014 13:09
Show Gist options
  • Save pzol/9208438 to your computer and use it in GitHub Desktop.
Save pzol/9208438 to your computer and use it in GitHub Desktop.
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