placeholder

Hasnain says:

This is nominally a post introducing a library, but it's so much more - I learnt a lot about good API design, string matching algorithms, and performance benchmarking. burntsushi's code and blogposts are always great, and this is no exception.

"In other words, if Rust’s primary string types work for your use case, then you should probably ignore bstr altogether and continue using them.

So why have a byte string library? The simplest way to explain it is to point at the std::io::Read trait. How does it work? Well, it says “anything implementing std::io::Read can take a writable slice of bytes, read from its underlying source and put the bytes from the source to the writable slice given.” Do you see anything missing? There’s no guarantee whatsoever about what those bytes are. They can be anything. They might be an image. They might be a video. Or a PDF. Or a plain text file.

In other words, the fundamental API we use to interact with data streams doesn’t make any guarantees about the nature of that stream. This is by design and it isn’t a Rust problem. On most mainstream operating systems, this is how files themselves are represented. They are just sequences of bytes. The format of those bytes usually exists at some other layer or is determined through some additional context."

Posted on 2022-09-08T19:51:15+0000