I have a simple question. This program throws an error:
fn main() {
let string_literal = "hello world";
println!("Here is an invalid slice: {}", string_literal[..3]);
// using &string_literal[..3] fixes this issue
}
That says the size for values of type `str` cannot be known at compilation time
I thought that because string_literal
is immutable, Rust could know its size.
What is happening and why would adding the ampersand fix it immediately, as shown in the comment in my function?
Thanks :)