How can i return vec from function

fn fibonacci(mut val1: i32, mut val2: i32, total: i32) -> Vec<i32> {
   let result = 0;
   let mut result1:Vec<i32> = Vec::new();
   for i in 1..(total + 1){
       result = val1 + val2;
       val1 = val2;
       val2 = result;
       result1.push(result);
   }
   result1
}

[edited to fix formatting –@mbrubeck]

You need to specify what kind of Vec you're returning. In this case it's Vec<i32>.

fn fibonacci(mut val1: i32, mut val2: i32, total: i32) -> Vec<i32> {
    let mut result = 0;
    let mut result1 = Vec::new();
    for i in 1..(total + 1) {
        result = val1 + val2;
        val1 = val2;
        val2 = result;
        result1.push(result);
    }
    result1
}

You can format your code like this,

```rust
// your code here
```

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.