rust-lang / rfcs

RFCs for changes to Rust
https://rust-lang.github.io/rfcs/
Apache License 2.0
5.98k stars 1.57k forks source link

Allocator adaptors for building strings and vectors with shared ownership. #1138

Open eddyb opened 9 years ago

eddyb commented 9 years ago

Assuming allocator support, and P<T, A=Heap> where P<T> is one of Box<T>, Rc<T>, Vec<T>, String, etc.: There could be an AsRc<A=Heap> allocator adaptor, which leaves space for a refcount when allocating and resizing an allocation.

We can then build a String<AsRc>, convert it to Box<str, AsRc> and convert that to Rc<str>, without any redundant copies.

This might also make an interesting alternative to polymorphic box: Rc::from(box foo) would work even if box expr: Box<T, A> (but it is even more verbose than Rc::new).

eddyb commented 9 years ago

cc @pnkfelix