Stebalien/horrorshow-rs

Feature request: render to `Bytes`

Lucretiel opened this issue · 3 comments

It's common in Rust web server frameworks to manage instances of bytes::Bytes, which is essentially a reference counted Vec. It's sufficiently ubiquitous that I think there'd be value in adding write_to_bytes or into_bytes to Template (perhaps behind a feature flag).

write_to_bytes is already implemented as write_to_io. If you want into_bytes, into_string().map(|s|s.into::<Vec<u8>>()) should do it. I'm not sure how a standalone into_bytes would improve this.

For some reason I had assumed that write_to_bytes would be faster for the same reason that write_to_string is faster than write_to_fmt. I'll do the into_string thing, thanks!

For some reason I had assumed that write_to_bytes would be faster for the same reason

Hm. You may be correct. Want to bench mark it?