When "overloaded box
" is implemented, could it be possible to do let s: String = box "hello";
? If so, this would make it clear that an allocation is taking place. Combined with box
patterns, this could also allow very ergonomic pattern matching on String
values.
This might look weird at first to modern Rust programmers, but remember that ~5
became box 5
, so it seems consistent that ~"hello"
would become box "hello"
. Vec
and String
are smart pointers to [T]
and str
respectively (for example, they implement Deref
), so constructing them should be consistent with constructing other smart pointers like Box<T>
and Rc<T>
.