首页 > 其他 > 详细

rust explicit

时间:2020-12-24 21:34:52      阅读:45      评论:0      收藏:0      [点我收藏+]

 

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

 

rust explicit

原文:https://www.cnblogs.com/dream397/p/14185379.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!