Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Get A Vec Of Uppercase Or Lowercase English Letters In Rust

rust
fn main() {
  dbg!(upper_case_letters());
  dbg!(lower_case_letters());
}

fn upper_case_letters() -> Vec<String> {
  (65..=90).map(|c| char::from_u32(c).unwrap().to_string()).collect()
}

fn lower_case_letters() -> Vec<String> {
  (97..=122).map(|c| char::from_u32(c).unwrap().to_string()).collect()
}
results start

Python has [TODO: Code shorthand span ] lc and [TODO: Code shorthand span ] uc to grab quick sets of ASCII letters. I haven't found anything like that in the Rust standard library. There's probably a crate that does it, but my quick search didn't turn up anything well maintained. The approach I'm using is to loop through the ASCII character codes to get the letters. Uppercase is 65 - 90 and lowercase is 97 - 122.

Since writing this I found a StackOverflow answer that uses this appraoch. (TODO : test that and write it up)

rust
('a'..='z').into_iter().collect::<Vec<char>>()

Footnotes And References