Created
February 3, 2024 10:09
-
-
Save jweinst1/c2a5ff576719f9f3507749a793da14bb to your computer and use it in GitHub Desktop.
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::rc::Rc; | |
use std::sync::{RwLock, Arc}; | |
use std::thread; | |
use std::collections::HashMap; | |
use std::collections::HashSet; | |
use std::fmt; | |
use std::clone::Clone; | |
fn main() { | |
let mut m:HashMap<Rc<String>, Rc<usize>> = HashMap::new(); | |
let fkey = Rc::new("foo".to_string()); | |
let key = Rc::new("foo".to_string()); | |
let key1 = Rc::clone(&key); | |
let val = Rc::new(6); | |
let val1 = Rc::clone(&val); | |
println!("key {:?}, val {:?}", Rc::strong_count(&key), Rc::strong_count(&val)); | |
m.insert(key1, val1); | |
println!("key {:?}, val {:?}", Rc::strong_count(&key), Rc::strong_count(&val)); | |
let lookup = m.get_key_value(&fkey).unwrap(); | |
println!("{:?} {:?}", lookup.0, lookup.1); | |
println!("key {:?}, val {:?}", Rc::strong_count(&key), Rc::strong_count(&val)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment