rust explicit

cat src/main.rs 
// 生命周期 `'a` 和 `'b`。这两个生命周期都必须至少要和 `print_refs`
// 函数的一样长。
fn print_refs<'a, 'b>(x: &'a i32, y: &'b i32) {
println!("x is {} and y is {}", x, y);
}
fn main() {
// 创建变量,给下面代码借用。
let (four, nine) = (4, 9);
// 两个变量的借用(`&`)都传进函数。
print_refs(&four, &four);
println!("four is {} and nine is {}", four, nine);
}
[root@bogon explicit]# cargo build
   Compiling own v0.1.0 (/data2/rust/explicit)
    Finished dev [unoptimized + debuginfo] target(s) in 0.34s
[root@bogon explicit]# cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/own`
x is 4 and y is 4
four is 4 and nine is 9
原文地址:https://www.cnblogs.com/dream397/p/14185379.html