Skip to content

Instantly share code, notes, and snippets.

@izgzhen
Created May 13, 2016 00:49
Show Gist options
  • Save izgzhen/e5b9d78c57152cc4db465e77b609c8d7 to your computer and use it in GitHub Desktop.
Save izgzhen/e5b9d78c57152cc4db465e77b609c8d7 to your computer and use it in GitHub Desktop.
trait Hash {
fn hash(&self) -> u64;
}
impl Hash for bool {
fn hash(&self) -> u64 {
if *self { 0 } else { 1 }
}
}
impl Hash for i64 {
fn hash(&self) -> u64 {
*self as u64
}
}
fn print_hash<T: Hash>(t: &T) {
println!("The hash is {}", t.hash())
}
struct HashMap<Key: Hash + Eq, Value> {
// Silly construct ... Just for demo purpose!
k: Key,
v: Value,
}
fn process(v: Vec<&Hash>) {
// whatever
}
fn main() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment