Skip to content

Instantly share code, notes, and snippets.

@peterschwarz
Forked from rust-play/playground.rs
Last active October 21, 2018 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterschwarz/b8066be33304523d897a691728e6c838 to your computer and use it in GitHub Desktop.
Save peterschwarz/b8066be33304523d897a691728e6c838 to your computer and use it in GitHub Desktop.
Symbol using Cow
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