base64-serde icon indicating copy to clipboard operation
base64-serde copied to clipboard

Use heap-free `Base64Display`

Open marshallpierce opened this issue 8 years ago • 0 comments

As per the commented out code in https://github.com/serde-rs/json/issues/360#issuecomment-330095360, we could use serializer.collect_str with the Display wrapper. However, that wrapper can only work with suitable configs (line wrap with length that is a multiple of 4 and not a crazy long line length). In practice, all configs that people are likely to use will satisfy this: MIME is the only common one that wraps, and it uses lines of 76 chars.

Options (not exhaustive):

  • Just expect("Programmer error: should've used a valid config") and hope for the best
  • Enhance the ChunkedEncoder implementation used by the Display wrapper to allow any Config
  • Define a ChunkedEncoderConfig that can only be constructed from a Config that is suitable, which we could then use to enforce via the type system that these things are only constructed in a valid way

@dtolnay thoughts?

marshallpierce avatar Sep 22 '17 13:09 marshallpierce