Answers to What are the differences between Rust's `String` and `str`? describe how &str
and String
relate to each other.
What is s
[T]
andstr
can't be stored on the stack, because they are both unsized
While this is true today, it may not be true in the future. RFC 1909 introduces unsized rvalues. One of the powers that this feature would give is variable-length arrays:
The RFC also describes an extension to the array literal syntax:
[e; dyn n]
. In the syntax,n
isn't necessarily a constant expression. The array is dynamically allocated on the stack
No mention is made of whether a string will be directly possible, but one could always create a stack-allocated array of bytes to be used as storage for a string.