for
2022/2/17 0:29:00
fn main() {
for c in "こんにちは".chars() {
println!("{}", c);
}
println!("");
let s:&str = "世界";
for c in s.chars() {
println!("{}", c);
}
}
こ
ん
に
ち
は
世
界
let v = vec![100, 32, 57];
for i in &v {
println!("{}", i);
}
/*
100
32
57
*/
let mut v = vec![100, 32, 57];
for i in &mut v {
*i += 50;
}
for i in &v {
println!("{}", i);
}
/*
150
82
107
*/
fn main() {
let s = String::from("こんにちは世界");
for b in s.chars() {
println!("{}", b);
}
}
こ
ん
に
ち
は
世
界
fn main() {
for b in "こんにちは".bytes() {
println!("{}", b);
}
println!("");
let s:&str = "世界";
for b in s.bytes() {
println!("{}", b);
}
}
227
129
147
227
130
147
227
129
171
227
129
161
227
129
175
228
184
150
231
149
140
fn main() {
enum SpreadsheetCell {
Int(i32),
Float(f64),
Text(String),
}
let row = vec![
SpreadsheetCell::Int(3),
SpreadsheetCell::Text(String::from("blue")),
SpreadsheetCell::Float(10.12),
];
for r in &row {
match r {
SpreadsheetCell::Int(i) => println!("{}", i),
SpreadsheetCell::Text(s) => println!("{}", s),
SpreadsheetCell::Float(f) => println!("{}", f),
}
}
}
3
blue
10.12
https://doc.rust-jp.rs/book-ja/ch08-01-vectors.html#enumを使って複数の型を保持する
fn main() {
for c in "👨👩👧👦".chars() {
println!("{}", c);
}
}
もしくは
fn main() {
let s = String::from("👨👩👧👦");
for c in s.chars() {
println!("{}", c);
}
}
👨
👩
👧
👦