rust学习(二)

play on line  

match if  
 1 #![allow(unused)]
 2 fn write_bar(size: u64){
 3     match size{
 4         o if o < 100 => println!("{:?} less than 100", o),
 5         o if o < 200 && o > 100  => println!("{:?} between 100-200", o),
 6         _ => println!("{:?} bigger than 200", size),
 7     }
 8 }
 9 fn main() {
10     write_bar(10);
11     write_bar(150);
12     write_bar(250);
13 }
View Code
 println!("{:#?}", 1)
 1 #[derive(Debug)]
 2 struct Teacher<'a> {
 3     name: &'a str,
 4     age1: u8
 5 }
 6 
 7 #[derive(Debug)]
 8 struct Person<'a> {
 9     name: &'a str,
10     age: u8
11 }
12 
13 fn main() {
14     let name = "Peter";
15     let mut age = 27;
16     let peter = Person { name, age };
17     
18     age = 22;
19     let lilei = Teacher{ name:"Lilei", age1:age};
20     // 美化打印
21     println!("{:#?}", lilei);
22     println!("{:#?}", peter);
23 }
View Code
 println! with param
1 #[derive(Debug)]
2 struct Complex { real: f32, imag: f32 }
3 
4 fn main() {
5     println!("The big range is {big:#?} and the small is {small}",
6              small = 0,
7              big = &[1, 2]);
8     println!("Debug: {:#?}", Complex{real: 2.2, imag: 7.2});
9 }
View Code
 try! 宏和 ? 一样
write!(f, "{}", value)?; 
try!(write!(f, "{}", value));

  

转载于:https://www.cnblogs.com/shaohef/p/11273590.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值