Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::HashMap;
- use std::sync::{Arc, Weak};
- trait MyTrait {}
- #[derive(Clone)]
- struct MyRef {
- inner: Weak<MyTrait>,
- }
- impl PartialEq for MyRef {
- fn eq(&self, other: &MyRef) -> bool {
- match (self.inner.upgrade(), other.inner.upgrade()) {
- (Some(ref me), Some(ref it)) => {
- Arc::ptr_eq(me, it)
- }
- _ => false,
- }
- }
- }
- struct Lookup {
- inner: HashMap<String, MyRef>,
- }
- impl Lookup {
- fn remove(&mut self, it: MyRef) {
- let matches: Vec<_> = self.inner
- .iter()
- .filter(|&(_, other)| *other == it)
- .map(|(k, _v)| k.clone())
- .collect();
- for m in matches {
- self.inner.remove(&m);
- }
- }
- }
- fn main() {
- }
Add Comment
Please, Sign In to add comment