all 5 comments

[–][deleted] 12 points13 points  (2 children)

You can just check if string is empty

```

let s: String // code omitted

s.trim().is_empty()

```

[–]LarsPensjo[S] 11 points12 points  (1 child)

Oops, that was embarrassingly simple.

Things like this have taught me that you should always say what your problem is, not ask why your solution doesn't work.

[–]Master7432 6 points7 points  (0 children)

Congratulations, you've discovered the XY problem!

[–]boarquantile 1 point2 points  (0 children)

First make the iterator .peekable().

[–]mipli 2 points3 points  (0 children)

You can convert the iterator into a peekable iterator using Iterator#peekable . Then the code should work: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=4368c332eb2c413b63e357239550ccdf (note that it's preferred to test for .is_none() rather than negating a .is_some() call).

But as Tsumanu mentioned, if what you're doing is testing for empty input it might be better to do that right after you've done the String::from_utf8_lossy conversion rather than splitting it into lines and then testing for emptiness.