fitzgen / bumpalo

A fast bump allocation arena for Rust
https://docs.rs/bumpalo
Apache License 2.0
1.34k stars 109 forks source link

Implement `std::io::Write` for `Vec<'bump, u8>` #215

Closed marmeladema closed 9 months ago

marmeladema commented 10 months ago

First of all, thank you for bumpalo, it's really awesome :)

I encountered a roadblock for a specific usecase recently when I wanted to use serde_json::to_writer on a Vec<'bump, u8> when I realized std::io::Write is not actually implemented whereas it is for Vec<u8> in the standard library: https://doc.rust-lang.org/std/io/trait.Write.html#impl-Write-for-Vec%3Cu8,+A%3E

There does not seem to be any technical limitation in bumpalo that would prevent from implementing it except:

Bumpalo is a no_std crate. It depends only on the alloc and core crates.

since std::io::Write is not available in core.

@fitzgen would you be inclined to accept a contribution that implement std::io::Write? Probably gated by a new std feature disabled by default?

Thank you for taking the time to read my request.

fitzgen commented 9 months ago

Yes, introducing a std feature that is disabled by default makes sense. Make sure to document the feature in the readme as well. Thanks!