Rust编程语言打字11_3.2.1
// An attribute to hide warnings for unused code.
#![allow(dead_code)]
enum Status {
Rich,
Poor,
}
enum Work {
Civilian,
Soldier,
}
fn main() {
// Explicitly `use` each name so they are available without
// manual scoping.
use Status::{Poor, Rich};
// Automatically `use` each name inside `Work`.
use Work::*;
// Equivalent to `Status::Poor`.
let status = Poor;
// Equivalent to `Work::Civilian`.
let work = Civilian;
match status {
// Note the lack of scoping because of the explicit `use` above.
Rich => println!("The rich have lots of money!"),
Poor => println!("The poor have no money..."),
}
match work {
// Note again the lack of scoping.
Civilian => println!("Civilians work!"),
Soldier => println!("Soldiers fight!"),
}
}
#![allow(dead_code)]
enum Status {
Rich,
Poor,
}
enum Work {
Civilian,
Soldier,
}
fn main() {
// Explicitly `use` each name so they are available without
// manual scoping.
use Status::{Poor, Rich};
// Automatically `use` each name inside `Work`.
use Work::*;
// Equivalent to `Status::Poor`.
let status = Poor;
// Equivalent to `Work::Civilian`.
let work = Civilian;
match status {
// Note the lack of scoping because of the explicit `use` above.
Rich => println!("The rich have lots of money!"),
Poor => println!("The poor have no money..."),
}
match work {
// Note again the lack of scoping.
Civilian => println!("Civilians work!"),
Soldier => println!("Soldiers fight!"),
}
}
上一篇:The Happy Door
下一篇:记忆、是什么?
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章熱度:☆☆☆☆☆
文章難度:☆☆☆☆☆
文章質量:☆☆☆☆☆
說明:系統根據文章的熱度、難度、質量自動認證,已認證的文章將參與打字排名!
本文打字排名TOP20
登录后可见
用户更多文章推荐
- Rust编程语言打字06_2.12017-01-14
- Rust编程语言打字04_Testcase: List2017-01-14
- Rust编程语言打字02_格式化输出_Debu...2017-01-14
- Rust编程语言打字03_格式化输出_Disp...2017-01-14
- Rust编程语言打字01_格式化输出2017-01-13