Index
- Guessing Game
- Common Programming Concepts
- Understanding Ownership
- Using Structs
- Enums and Pattern Matching
- Managing Growing Projects with Packages, Crates, and Modules
- Defining Modules to Control Scope and Privacy
- Paths for Referring to an Item in the Module Tree
- Bringing Paths into Scope with the use Keyword
- Separating Modules into Different Files
- Common Collections
- Error Handling
- Generic Types, Traits, and Lifetimes
- Writing Automated Tests
- Object Oriented Programming
- Adding dependancies
- Option Take
- RefCell
- mem
- Data Structure
- Recipe
- Semi colon
- Calling rust from python
- Default
- Crytocurrency With rust
- Function chaining
- Question Mark Operator
- Tests with println
- lib and bin
- Append vector to hash map
- Random Number
- uuid4
- uwrap and option
- Blockchain with Rust
- Near Protocol
- Actix-web
Append vector to hash map
https://stackoverflow.com/questions/33243784/append-to-vector-as-value-of-hashmapThe get method only takes &self, so it’s immutable – use get_mut instead.
Append to vector as value of hashmap
for token in lorem.split_whitespace() {
if prefix[0] != "" {
let key = prefix.join(" ");
match dict.entry(key) {
Entry::Vacant(e) => { e.insert(vec![token]); },
Entry::Occupied(mut e) => { e.get_mut().push(token); }
}
}
prefix[0] = prefix[1];
prefix[1] = token;
}
if prefix[0] != "" {
let key = prefix.join(" ");
match dict.entry(key) {
Entry::Vacant(e) => { e.insert(vec![token]); },
Entry::Occupied(mut e) => { e.get_mut().push(token); }
}
}
prefix[0] = prefix[1];
prefix[1] = token;
}
for token in lorem.split_whitespace() {
if prefix[0] != "" {
let key = prefix.join(" ");
dict.entry(key).or_insert(Vec::new()).push(token);
}
prefix[0] = prefix[1];
prefix[1] = token;
}
if prefix[0] != "" {
let key = prefix.join(" ");
dict.entry(key).or_insert(Vec::new()).push(token);
}
prefix[0] = prefix[1];
prefix[1] = token;
}