vcombey / fallible_collections

impl fallible collections in rust, quite as describe in RFC 2116
Apache License 2.0
31 stars 14 forks source link

TryVec does not implement std::io::Write #26

Closed IanE9 closed 2 years ago

IanE9 commented 2 years ago

Without getting into too much detail, I'm trying to use TryVec as a drop in replacement for Vec for some existing code with the intent of protecting against panics during an OOM scenario and unable to do so because TryVec does not implement std::io::Write.

Minimal example:

use fallible_collections::TryVec;

fn foo(bar: &mut impl std::io::Write) -> Result<(), std::io::Error> {
    bar.write_all("baz".as_bytes())
}

fn compiles() -> Result<Vec<u8>, std::io::Error> {
    let mut vec = Vec::new();
    foo(&mut vec)?;
    Ok(vec)
}

fn doesnt_compile() -> Result<TryVec<u8>, std::io::Error> {
    let mut vec = TryVec::new();
    foo(&mut vec)?; // the trait `std::io::Write` is not implemented for `TryVec<_>`
    Ok(vec)
}

Is this an oversight or is there some strong reason for not having TryVec implement std::io::Write?

IanE9 commented 2 years ago

Ah, my mistake. It looks like this functionality is already available, just beneath the std_io feature option.