码迷,mamicode.com
首页 > 其他好文 > 详细

rust学习(二)

时间:2019-07-31 01:11:35      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:teacher   code   rust   class   get   target   match   between   splay   

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

 

rust学习(二)

标签:teacher   code   rust   class   get   target   match   between   splay   

原文地址:https://www.cnblogs.com/shaohef/p/11273590.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!