I'm working on a toy HTTP parser, and as it's incorrect to assume that HTTP communications are valid UTF-8, I'm using bytes everywhere. For Debug impls, I'm using BStr to display things like the request method, header names and values, etc. However, this only works where I have access to a byte slice that already contains the exact bytes I want to use with BStr's formatting machinery; it breaks down in the face of things like percent-encoding.
For instance, I may want to re-use BStr's Display machinery for path segments. In order to do this:
- I could transplant the machinery into my project and make tweaks for it to handle percent-decoding. I don't want to do this even if it's unlikely to change.
- I could mutate the slice in-place to obtain something contiguous to pass to BStr. I was considering doing this as segments are returned from the iterator, but I decided against it because mutating the slice in-place loses information about which bytes were percent-encoded, which I may still want to surface through Debug.
- I could allocate memory.
- BStr could expose parts of its machinery so that I wouldn't have to vendor it or massage memory contents.
If I could use BStr's machinery with an iterator of bytes rather than a slice, that would be perfect, but reading through the code I'm not sure that'd be very easy to implement.
I'm working on a toy HTTP parser, and as it's incorrect to assume that HTTP communications are valid UTF-8, I'm using bytes everywhere. For Debug impls, I'm using BStr to display things like the request method, header names and values, etc. However, this only works where I have access to a byte slice that already contains the exact bytes I want to use with BStr's formatting machinery; it breaks down in the face of things like percent-encoding.
For instance, I may want to re-use BStr's Display machinery for path segments. In order to do this:
If I could use BStr's machinery with an iterator of bytes rather than a slice, that would be perfect, but reading through the code I'm not sure that'd be very easy to implement.