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:
- Implement
std::io::Write for SmallString so I can use std::io::copy().
- Add
SmallString::read<R: Read>(r: &mut R)
- 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.
- 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.
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:
std::io::WriteforSmallStringso I can usestd::io::copy().SmallString::read<R: Read>(r: &mut R)from_small_vec(data: SmallVec<A>). SinceSmallVecalready implementsstd::io::Write, I could usestd::io::copy()again. Not as efficient as the others, be cause this would require to move theSmallVecintoSmallStringwhich is not free.smallstr::ReadExttrait which is implemented for allT: Readand provides a methodread_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.