Sometimes it is useful to create a string from a string literal but also want to make sure that there is extra space for future additions. It is currently possible to do the following:
let mut s = String::reserve(56); s.push_str("foobar");
However I think it would be clearer in most cases to have something like the following:
let s = String::from_reserve("foobar", 50);
These two behave the same (modulo non-exact allocations). But I would argue that the second is clear in its intent. Plus since it is reserving space in addition (since that is how the reserve method works), you don't need to manually calculate the difference (like in the first case).
- What should this function be called?
- Should we have an exact counterpoint as well?
- Does this need to be an RFC or could I just submit a PR for an unstable associated functions?