()
is expected because this if
lacks the else branch. You can either change this if to early return:
if self.input_args.len() != 0 {
return self.input_args.iter()
}
or put the rest of the function in the else
branch.
There are also some other issues with the code. Here you try to borrow a temporary String
(line
):
stdin().lock().lines().into_iter()
.map(|line| &line.expect("IO error"))
this will result in "does not live long enough" error. The simplest solution would be to change Item=&String
to Item=String
(in general, if you return a reference, the true owner needs to already exist before calling the function).
Also, Rust won't allow you to return two different iterators in a -> impl Iterator
function. You can work around that by returning Box<dyn Iterator>
or using enum approach, eg. by using the either
crate. Here's a thread describing a similar issue. And another one.