Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
DrEden33773 committed Mar 1, 2024
1 parent c9f8a42 commit 4f85bd7
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/playground.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#![allow(dead_code)]

mod p {
use std::{collections::HashMap, hash::Hash};
use std::{
collections::HashMap,
fmt::{Debug, Display},
hash::Hash,
};

struct User {
id: u128,
id: u64,
name: String,
}

impl Display for User {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "User {{ id: {}, name: {} }}", self.id, self.name)
}
}

struct Room<'a, K: Hash + Clone + Eq, V: Clone> {
key_refs: Vec<&'a K>,
map: HashMap<K, V>,
Expand Down Expand Up @@ -55,4 +65,28 @@ mod p {
println!("{}: {}", i, e);
}
}

struct Wrapper<K: Hash, V>(HashMap<K, V>);

struct NamedWrapper<K: Hash, V> {
pub val: HashMap<K, V>,
}

fn receiver<K: Hash + Debug, V: Debug>(Wrapper(map): Wrapper<K, V>) {
println!("{:?}", map);
}

fn named_receiver<K: Hash + Debug, V: Debug>(NamedWrapper { val }: NamedWrapper<K, V>) {
println!("{:?}", val);
}

#[test]
fn test_receiver() {
let map = vec![("a", 1), ("b", 2), ("c", 3)]
.into_iter()
.collect::<HashMap<_, _>>();

receiver(Wrapper(map.clone()));
named_receiver(NamedWrapper { val: map });
}
}

0 comments on commit 4f85bd7

Please sign in to comment.