Skip to content

Expose the formatting primitives used inside BStr's Debug and Display impls? #225

@LoganDark

Description

@LoganDark

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions