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).
Assuming allocator support, and
P<T, A=Heap>
whereP<T>
is one ofBox<T>
,Rc<T>
,Vec<T>
,String
, etc.: There could be anAsRc<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 toBox<str, AsRc>
and convert that toRc<str>
, without any redundant copies.This might also make an interesting alternative to polymorphic
box
:Rc::from(box foo)
would work even ifbox expr: Box<T, A>
(but it is even more verbose thanRc::new
).