HI All,
I'm new to rust and enjoying it so far, just trying to get a handle on some things like this...
This method compiles and works fine:
fn make_ay(word: &str) -> String {
let s = format!("{}-{}ay ",&word[1..word.len()], &word[0..1]);
s
}
but, if I remove the 'let' and try to return the formatted string, whatever I try complains that the length isn't known at compile time. Adding the 'let' fixes it.
Does this have something to do with the stack vs heap? Does the method without the 'let' try to use the stack and therefore needs to know the length? Or, have I completely misunderstood?
Either way, I'm trying to understand why 'let' is the only way i can make this work rather than just accepting that it does