-
-
Save peterschwarz/b8066be33304523d897a691728e6c838 to your computer and use it in GitHub Desktop.
Symbol using Cow
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