Created
October 7, 2018 20:44
-
-
Save rust-play/92ffa1804259a8508d998d9d15bdf4ab 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::borrow::Cow; | |
use std::collections::HashMap; | |
#[derive(Eq, PartialEq, Hash, Clone, Default, Debug)] | |
struct Symbol<'a> { | |
ns: Cow<'a, str>, | |
name: Cow<'a, str>, | |
} | |
impl<'a> Symbol<'a> { | |
fn new(ns: &'a str, name: &'a str) -> Self { | |
Symbol { | |
ns: Cow::from(ns), | |
name: Cow::from(name), | |
} | |
} | |
} | |
fn main() { | |
let mut m: HashMap<Symbol, u32> = HashMap::default(); | |
m.insert(Symbol::new("some-ns", "key"), 100); | |
println!("{:?}", m); | |
println!("v: {:?}", m.get(&Symbol::new("some-ns", "key"))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment