fitzgen / bumpalo

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

Idea: ToBumpString #74

Open richard-uk1 opened 4 years ago

richard-uk1 commented 4 years ago

I find I end up writing

let x = bumpalo::format!(in cx.bump, "{}", var).into_bump_str();

a lot, so my suggestion is to add

trait ToBumpString: Display {
    fn to_bump_str<'a>(&self, arena: &'a Bump) -> &'a str {
        bumpalo::format!(in arena, "{}", var).into_bump_str();
    }

matching ToString (except that we want a &str).

fitzgen commented 4 years ago

This makes sense to me, but in the bumpalo crate.

ToString doesn't require Display, but instead has a blanket implementation for all T: Display. I think it makes sense to copy that here.