error: the order of `mut` and `ref` is incorrect
--> src/main.rs:14:14
|
14 | Some(mut ref age) => {
| ^^^^^^^ help: try switching the order: `ref mut`
error: aborting due to previous error
练习2
您需要为要交换的两个参数提供可变引用。 此外,为了获得对 res 的可变引用,res 本身需要是可变的:
fn next(&mut self) -> Option<T> {
let mut res = None;
std::mem::swap(&mut res, &mut self.next);
res
}
练习3
我们需要两个不同的参数,并确保 ret 和返回值具有相同的生存期参数:
fn message_and_return<'a, 'b>(msg: &'a String, ret: &'b String) -> &'b String {
println!("Printing the message: {}", msg);
ret
}
fn main() {
let bytearray1: &'static [u8; 22] = b"Hello World in binary!";
let bytearray2: &'static [u8] = b"Hello World in binary!";
println!("{:?}", bytearray1);
println!("{:?}", bytearray2);
}