summaryrefslogtreecommitdiff
path: root/rust-book/collections
diff options
context:
space:
mode:
authorAdam Carpenter <53hornet@gmail.com>2019-03-27 15:32:37 -0400
committerAdam Carpenter <53hornet@gmail.com>2019-03-27 15:32:37 -0400
commit67cdcc2e12118becb823e20a40cc2687f2b8425a (patch)
treeed92c3234b89079e6d4cf36f5e80c5ffa79def48 /rust-book/collections
parente25482fca375d318a39c3b54db396b0db6e0b263 (diff)
downloadlearning-rust-67cdcc2e12118becb823e20a40cc2687f2b8425a.tar.xz
learning-rust-67cdcc2e12118becb823e20a40cc2687f2b8425a.zip
Started Rust in Action MEAP.
Diffstat (limited to 'rust-book/collections')
-rwxr-xr-xrust-book/collections/Cargo.lock4
-rwxr-xr-xrust-book/collections/Cargo.toml7
-rwxr-xr-xrust-book/collections/src/main.rs133
3 files changed, 144 insertions, 0 deletions
diff --git a/rust-book/collections/Cargo.lock b/rust-book/collections/Cargo.lock
new file mode 100755
index 0000000..14856a6
--- /dev/null
+++ b/rust-book/collections/Cargo.lock
@@ -0,0 +1,4 @@
+[[package]]
+name = "collections"
+version = "0.1.0"
+
diff --git a/rust-book/collections/Cargo.toml b/rust-book/collections/Cargo.toml
new file mode 100755
index 0000000..8460a0c
--- /dev/null
+++ b/rust-book/collections/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "collections"
+version = "0.1.0"
+authors = ["Adam Carpenter <carpenat@ES.AD.ADP.COM>"]
+edition = "2018"
+
+[dependencies]
diff --git a/rust-book/collections/src/main.rs b/rust-book/collections/src/main.rs
new file mode 100755
index 0000000..7257ce2
--- /dev/null
+++ b/rust-book/collections/src/main.rs
@@ -0,0 +1,133 @@
+use std::collections::HashMap;
+
+fn main() {
+ //let v: Vec<i32> = Vec::new();
+ //let mut v = vec![1, 2, 3, 4, 5];
+
+ // let third: &i32 = &v[2];
+ // println!("the third element is {}", third);
+ //
+ // match v.get(2) {
+ // Some(third) => println!("third is {}", third),
+ // None => println!("no third element"),
+ // }
+ //
+ // for i in &mut v {
+ // *i += 10;
+ // println!("{}", *i);
+ // }
+ // for i in &v {
+ // println!("{}", i);
+ // }
+
+ // enum SpreadsheetCell {
+ // Int(i32),
+ // Float(f64),
+ // Text(String),
+ // }
+ //
+ // let row = vec![
+ // SpreadsheetCell::Int(3),
+ // SpreadsheetCell::Text(String::from("blue")),
+ // SpreadsheetCell::Float(10.12),
+ // ];
+
+ //let mut s = String::new();
+
+ //let data = "initial contents";
+ //let s = data.to_string();
+ //dbg!(s);
+ //let s = "initial contents".to_string();
+ //dbg!(s);
+ //let s = String::from("initial contents");
+ //dbg!(s);
+
+ //let mut s = String::from("hello");
+ //s.push_str(" world");
+
+ //let mut s1 = String::from("hello");
+ //let s2 = " world";
+ //s1.push_str(s2);
+ //s1.push('!');
+ //dbg!(s1);
+
+ //let s1 = String::from("Hello ");
+ //let s2 = String::from("world");
+ //let s3 = s1 + &s2 + "!";
+ //dbg!(s3);
+
+ //let my_result: Result<&'static str, &'static str> = Ok("test");
+
+ //dbg!(my_result);
+
+ //let s1 = String::from("tic");
+ //let s2 = String::from("tac");
+ //let s3 = String::from("toe");
+
+ //let s = format!("{}-{}-{}", s1, s2, s3);
+ //dbg!(s);
+
+ //let s = String::from("welcome to hello world");
+ //let len = s.len();
+ //dbg!(len);
+ //let s1 = s[0..15].to_string();
+ //dbg!(s1);
+
+ //for c in "hello world".bytes() {
+ // dbg!(c);
+ //}
+
+ //let mut scores = HashMap::new();
+ //scores.insert(String::from("Blue"), 10);
+ //scores.insert(String::from("Yellow"), 50);
+ //scores.insert(String::from("Blue"), 20);
+ //dbg!(scores);
+
+ //let teams = vec![String::from("blue"), String::from("yellow")];
+ //let initial_scores = vec![10, 20];
+ //let scores: HashMap<_, _> = teams.iter().zip(initial_scores.iter()).collect();
+ //dbg!(scores);
+
+ //let field_name = String::from("favorite color");
+ //let field_value = String::from("blue");
+
+ //let mut map = HashMap::new();
+ //map.insert(field_name, field_value);
+
+ //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);
+
+ //dbg!(team_name);
+ //dbg!(score);
+
+ //let mut scores = HashMap::new();
+
+ //scores.insert(String::from("blue"), 10);
+ //scores.insert(String::from("yellow"), 50);
+
+ //for (key, value) in &scores {
+ // dbg!(key);
+ // dbg!(value);
+ //}
+
+ // let mut scores = HashMap::new();
+ // scores.insert(String::from("blue"), 10);
+ // scores.entry(String::from("yellow")).or_insert(50);
+ // scores.entry(String::from("blue")).or_insert(50);
+ // dbg!(scores);
+
+ //let text = "when in the course of himan events it becomes necessary for one people to dissolve the political bands which have connected them with another and to assume among the powers of the earth the separate and equal station to which thelaws of nature and of nature's God entitle them a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation";
+ //let mut map = HashMap::new();
+
+ //for word in text.split_whitespace() {
+ // let count = map.entry(word).or_insert(0);
+ // *count += 1;
+ //}
+
+ //dbg!(map);
+
+}