2 ms·
Amusingly if you create a Vec or String that operation is guaranteed not to allocate :D The new() functions for these types are const (ie they can be evaluated
by tialaramex 5y ago
Amusingly if you create a Vec or String that operation is guaranteed not to allocate :D
The new() functions for these types are const (ie they can be evaluated at compile time) and produce an "empty" placeholder.
Because Rust's Strings don't have NUL termination, the empty string doesn't need any backing storage, likewise for an empty vector.
When (and more importantly in many programs if) you actually add something to the string or vector that may prompt an allocation, but you called an explicit method to do that, so it oughtn't to come as any surprise.