I'm quite new to Rust, I wanted to write a really simple Caeser cipher which moves every letter forward by 1 in the alphabet, but I get this error, and I couldn't figure out the exact cause. I'd appreciate any suggestions about what I'm doing wrong.
use std::io;
fn main(){
let letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let mut buffer: Vec<char> = Vec::new();
let mut s = String::new();
io::stdin().read_line(&mut s)
.expect("Cannot read input!");
for _char in s.chars() {
let index = letters.chars().position(|r| r == _char).unwrap();
let new_index = index+1 % letters.len();
buffer.push(letters.chars().nth(new_index).unwrap());
}
for _char in buffer.iter() {
print!("{}", _char);
}
}
Error: thread 'main' panicked at 'called Option::unwrap()
on a None
value'