I'm trying to use string.chars().peekable() and the problem I have is that I have different types from .next() and .peek(). One is Option<char>, second is Option<&char>, and I have trouble to compare them.
My code is (s is String):
let mut left_iter = s.chars().peekable();
let mut right_iter = s.chars().rev().peekable();
loop {
let left = left_iter.next();
let right = right_iter.next();
let left_next = left_iter.peek();
let left_right = right_iter.peek();
if left == right || left == right_next {
...
}
The error I get is obvious:
expected &char, found char
But I can't find a way to have both next() and peek() having the same type without re/deconstructing Option.
Is there a clean way to have both return values having the same type?