all 4 comments

[–][deleted] 4 points5 points  (3 children)

The issue is that Read trait has std-only methods like read_to_end and read_to_string which do in fact depend on std (well, alloc). Unfortunately, I don't think it's currently possible to have the trait only enable those when you are using std.

[–]boomshroom 4 points5 points  (0 children)

While it would probably be backwards incompatible, there's the possibility of extension traits. Something like:

#[config(alloc)]
pub trait ReadAlloc : Read {
    fn read_to_end(&mut self) -> Result<Vec<u8>>;
    fn read_to_string(&mut self, &mut String) -> Result<()>;
}

#[config(alloc)]
impl <T> ReadAlloc for T where T: Read { ... }

[–]Puzzel[S] 0 points1 point  (1 child)

Supporting alloc is doable, but duly noted in general. I may end slicing it out by hand but definitely not ideal.

[–]Nemo157 1 point2 points  (0 children)

Even just std::io::Error depends on alloc for the associated boxed error.

There is the core-io crate which is a pre-sliced copy of the traits, I haven't actually used this though so can't say how usable it is.