Trying to set numbers into word form

I am a slight beginner in Rust and I am trying to set numbers 0-9 into word form. My code is erroring "and says expected type, found keyword static". I don't know what this means and I was hoping someone would help me understand and how to fix it.

pub fn run(){

fn run(n: usize) -> &static str {

 let  n:[i32; 10]=[0,1,2,3,4,5,6,7,8,9];

     println!("{zero} {one} {two} {three} {four} {five} {six} {seven} {eight} {nine}", n[0,1,2,3,4,5,6,7,8,9,10]);

}}

There are a few issues in your code snippet:

  • println returns the unit (()) type, not &str
  • The bracket notation to access array elements by index only supports one element
  • String interpolation doesn't work like that in Rust, you are calling variables that are not defined anywhere in the code
2 Likes

Is something like this what you were aiming for?

fn main() {
    for n in 0..10 {
        println!("{n}: {}", run(n));
    }
}

fn run(n: usize) -> &'static str {
    const WORDS: [&'static str; 10] = [
        "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
    ];

    &WORDS[n]
}
1 Like

Thanks for the help and tips

its saying "there is no argument named 'n'"

Did you copy 2e71828's code from the playground? His code snippet is clearly working.

What version of the compiler are you using?

I just updated to 1.59 but it still doesn't work

I just found out it was a 0 width space unicode