I quote the official documentation:
A reference represents a borrow of some owned value.
Coming from C, Java, Perl and PHP, I see a "reference" as an address (or pointer) to a value. It is possible to declare a variable of type "T" or a reference (or pointer) to a variable of type "T" (using &
- or \
in Perl).
However, I am not sure that this representation is totally valid with Rust. Something bothers me.
I always see the "string slice" manipulated as a reference, that is, in its borrowed form (&str
).
I have (so far) never seen a variable of type "str
".
I tried to declare a variable of type "str
"... but the compiler does not let me do that.
QUESTION: can we define a variable of type "str
" ?
If it is impossible, then it means that we are facing a type of data that cannot be declared other than as a reference. This seems weird...