Created
December 5, 2019 20:13
-
-
Save rust-play/dcb43521a1ad2c77b3ce9b91cdb312a2 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
struct Foo { | |
d: HashMap<String, f32> | |
} | |
impl Foo { | |
fn get(&mut self, s: &str) -> Option<&f32> { | |
if !self.d.contains_key(s) { | |
self.d.insert(s.to_string(), 0.0); | |
} | |
self.d.get(s) | |
} | |
} | |
fn main() { | |
let mut foo = Foo { | |
d: HashMap::new() | |
}; | |
let mut saved = Vec::new(); | |
for _i in 1..3 { | |
let l = foo.get("a"); | |
saved.push(l); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment