Mercurial > hg > Members > kono > rust-tutorial
changeset 4:3d23e8517403
option
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 12 Jan 2021 10:35:31 +0900 |
parents | 9bb0201e638b |
children | e869e24e5613 |
files | guessing/src/main.rs src/t01guessing/src/main.rs |
diffstat | 2 files changed, 37 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/guessing/src/main.rs Mon Jan 11 19:17:21 2021 +0900 +++ b/guessing/src/main.rs Tue Jan 12 10:35:31 2021 +0900 @@ -1,3 +1,21 @@ -fn main() { +// #![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 main() -> std::io::Result<()> { println!("Hello, guessing!"); + main1(); + Ok(()) }
--- a/src/t01guessing/src/main.rs Mon Jan 11 19:17:21 2021 +0900 +++ b/src/t01guessing/src/main.rs Tue Jan 12 10:35:31 2021 +0900 @@ -14,6 +14,24 @@ println!("Please input your guess."); let mut guess = String::new(); + // let a = [[1.0,2.0],[3.0,0.1]]; + // println!("a = {} {}",a[1][1],a[0][0]); + let /* mut */ s1 = String::from("hello"); + let s2 = s1; + let hello = "Здравствуйте"; + // s1 = s2; + let answer = match hello.chars().nth(1) { + Some(c) => c, + None => continue, + }; + + println!("{}, world! {}", s2,answer); + + let mut j = 0; + for i in 0 .. 10 { + j += i; + } + println!("{}",j); io::stdin() .read_line(&mut guess)