Vector
let v: Vec<i32> = Vec::new();
let mut v1 = vec![1, 2, 3, 4];
v1.push(5);
let c = &v1[1];
match v1.get(1) {
Some(x) => println!("{}", x),
None => println!("None"),
}
enum Cell {
Int(i32),
Float(f64),
Text(String),
}
let row = vec![
Cell::Int(3),
Cell::Float(2.0),
Cell::Text(String::from("str")),
];
String
let mut s = String::new();
let s1 = String::from("ssss");
let s2 = "ssss".to_string();
let s3 = &s1[..];
s.push_str(&s3);
s.push('l');
let s4 = s + &s1;
println!("{}", format!("{}-{}-{}", s1, s2, s4));
for i in s4.bytes() {
println!("{}", i);
}
for i in s4.chars() {
println!("{}", i);
}
HashMap
use std::collections::HashMap;
let mut table: HashMap<i32, f32> = HashMap::new();
table.insert(23, 3.0);
let key = vec![10, 20];
let value = vec![1.0, 2.0];
let mut table2: HashMap<_, _> = key.iter().zip(value.iter()).collect();
if let Some(x) = table2.get(&10) {
println!("v:{}", x);
} else {
println!("none");
}
for (k, v) in &table2 {
println!("{}:{}", k, v);
}
let a = table2.entry(&10).or_insert(&3.0);
println!("{:?}", table2.entry(&10));
println!("{:?}", table2.entry(&30));