Skip to content

Efficiently creating a SmallString from std::io::Read #19

@dwuertz

Description

@dwuertz

I'm looking for an alternative for https://doc.rust-lang.org/std/io/trait.Read.html#method.read_to_string that works with SmallString. So far I haven't found any solutions that doesn't involve additional copies or allocs. I believe an API enhancement is needed somehow. Can you please confirm or otherwise suggest a solution?

I could think of various ways to achieve my goal:

  1. Implement std::io::Write for SmallString so I can use std::io::copy().
  2. Add SmallString::read<R: Read>(r: &mut R)
  3. Add new constructor from_small_vec(data: SmallVec<A>). Since SmallVec already implements std::io::Write, I could use std::io::copy() again. Not as efficient as the others, be cause this would require to move the SmallVec into SmallStringwhich is not free.
  4. Add a smallstr::ReadExt trait which is implemented for all T: Read and provides a method read_to_small_str().

I would be willing to work on this myself, but would first appreciate a feedback from the crate's maintainer, which way to favor.

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