News for hackers. Stuff that matters.
Re:A rough proposal for sum types in Go (2018) by tialaramex on Monday November 15, 2021 @05:51PM (#29233992)
That's not an error then, or, that's not what I'd consider a result, or both.

Compare Rust's https://doc.rust-lang.org/std/str/fn.from_utf8.html

If you've got a buffer full of bytes, which you hope are UTF8 text but maybe aren't, call std::str::from_utf8 and you either get back a string slice with your text in it, or you get a std::str::Utf8Error structure which explains what the problem was in an actionable format. You can write code to process this Utf8Error and your bytes - maybe you're reading blocks of data and it's all valid UTF8 but the last character is continued in the next block for example, you can discern that from Utf8Error and just turn the valid part into UTF8 and keep the rest until the next block is available.

There are no comments on this comment yet.