struct SomeIterator<'a> {
chars: Chars<'a>,
}
impl<'a> SomeIterator<'a> {
fn is_something(&self, ch: Option<char>) -> bool {
ch.is_some()
}
}
impl<'a> Iterator for SomeIterator<'a> {
type Item = ();
fn next(&mut self) -> Option<Self::Item> {
// This triggers the borrow checker
self.is_something(self.chars.next()).then_some(())
// But this doesn't...
// let maybe_ch = self.chars.next();
// self.is_something(maybe_ch).then_some(())
}
}
I came across this borrow checker warning (I have constructed a contrived example to demonstrate), but discovered that simply by assigning to a variable before passing to a function satisfies the check.
Is this something that could simply be changed with the borrow checker, as it appears the solution for making it work appears trivial?