How to generate `Vec<u32>`

with a recurrence relation like a[n]=3a[n-1]+1, a[0] = 1 bounded by 1000?

Following code does but is there any better way? (does it use `fold`

or something?)

```
let mut v = vec![];
let mut next = 1;
let f = |x: u32| x * 3 + 1;
loop {
if next > 1000 {
break;
}
v.push(next);
next = f(next);
}
// v = [1, 4, 13, 40, 121, 364]
```

cf. Haskell:

```
takeWhile (<= 1000) $ iterate (\x -> x*3 + 1) 1
```

Thanks.