How to manage InvalidData error when reading a file

Hi all,

When reading a file with read_line(), you can get an InvalidData error, if the underlying text is not UTF-8.

So how to cope with this error? Once the error is triggered, you can't switch to a lossy version of the string. Do I have to switch to read_until() and use lossy methods?

Thanks for your help, which is, as always, invaluable :slight_smile:

If your data is not utf-8, you should read into a vector using e.g. read_until as you suggested.

@alice thanks. That's what I expected. Data is mainly UTF-8 but some garbage could surface sometimes.

The bstr crate is very useful for reading and processing data that is "mainly UTF-8 but..."


Thanks, I'll have a look !

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.