Mercurial > hg > Members > kono > rust-tutorial
view guessing/src/main.rs @ 5:e869e24e5613
thread test
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 12 Jan 2021 11:34:52 +0900 |
parents | 3d23e8517403 |
children |
line wrap: on
line source
// #![feature(termination_trait)] fn main1() -> Option<u32> { use std::collections::HashMap; let mut scores = HashMap::new(); scores.insert(String::from("Blue"), 10); scores.insert(String::from("Yellow"), 50); let team_name = String::from("Blue"); let score = scores.get(&team_name)?; println!("result {}",score); Some(1) } fn main3() { let x = 4; //fn equal_to_x(z: i32) -> bool { // z == x //} let equal_to_x = | z | z == x; let y = 4; assert!(equal_to_x(y)); } fn main2() { let x = 3 ; // vec![1, 2, 3]; let equal_to_x = move |z| z == x; println!("can't use x here: {:?}", x); let y = 3 ; // vec![1, 2, 3]; assert!(equal_to_x(y)); } fn main() -> std::io::Result<()> { println!("Hello, guessing!"); main1(); main2(); main3(); Ok(()) }