Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created October 7, 2018 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rust-play/92ffa1804259a8508d998d9d15bdf4ab to your computer and use it in GitHub Desktop.
Save rust-play/92ffa1804259a8508d998d9d15bdf4ab to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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