8 コレクション #8
lemonadern
started this conversation in
General
Replies: 4 comments 10 replies
-
ベクタ
|
Beta Was this translation helpful? Give feedback.
5 replies
-
String
文字列の生成 let mut s = String::new(); 文字列リテラルから let s = "initial contents".to_string();
let mut s = String::from("foo");
s.push_str("bar"); // push_str は所有権を奪わない
let mut s = String::from("lo");
s.push('l'); 文字列の連結
let s1 = String::from("Hello, ");
let s2 = String::from("world!");
let s3 = s1 + &s2; // s1はムーブされ、もう使用できない
let s1 = String::from("tic");
let s2 = String::from("tac");
let s3 = String::from("toe");
let s = format!("{}-{}-{}", s1, s2, s3); |
Beta Was this translation helpful? Give feedback.
2 replies
-
ハッシュマップ
ハッシュマップの生成 use std::collections::HashMap;
let mut scores = HashMap::new(); キーと、それに紐づく値の挿入
scores.insert(String::from("Blue"), 10);
scores.insert(String::from("Yellow"), 50); チームのリスト・スコアのリストからハッシュマップをつくる use std::collections::HashMap;
let teams = vec![String::from("Blue"), String::from("Yellow")];
let initial_scores = vec![10, 50];
let scores: HashMap<_, _> = teams.iter().zip(initial_scores.iter()).collect(); ループでハッシュマップを走査する for (key, value) in &scores {
println!("{}: {}", key, value);
} |
Beta Was this translation helpful? Give feedback.
2 replies
-
練習問題 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
https://doc.rust-jp.rs/book-ja/ch08-00-common-collections.html
Beta Was this translation helpful? Give feedback.
All reactions