我在Rust中做了一个Leetcode问题,遇到了以下错误:
fn plus_one(digits: &mut Vec<u32>) -> &Vec<u32> {
for i in (0.. digits.len()).rev() {
if digits[i] < 10 {
digits[i] = digits[i] + 1;
break;
}else{
digits[i] = 0;
}
}
if(digits[0] == 0) {
let mut new_digits : Vec<u32> = vec![1];
new_digits.extend(digits). // This is the error
}
digits
}
GET错误:
--> src/easy/plus_one.rs:13:20
|
13 | new_digits.extend(digits)
| ^^^^^^ the trait `Extend<&mut u32>` is not implemented for `Vec<u32>`
|
= help: the following other types implement trait `Extend<A>`:
<Vec<T, A> as Extend<T>>
<Vec<T, A> as Extend<&'a T>>
问题出在哪里?我该如何解决这个问题?