| 20 | |
| 21 | impl StorageInner { |
| 22 | pub(crate) fn get(&mut self, key: &(u64, String)) -> Option<AnyResource> { |
| 23 | if let Some(resource) = self.resources.get_mut(key) { |
| 24 | if let Ok(res) = resource.get() { |
| 25 | return Some(res.clone()); |
| 26 | } else { |
| 27 | resource.revert(); |
| 28 | } |
| 29 | } else { |
| 30 | return None; |
| 31 | } |
| 32 | for v in self.resources.values_mut() { |
| 33 | if let Some(Ok(res)) = v.view() { |
| 34 | // it is safe because of `&mut self` |
| 35 | if Arc::strong_count(res) == 1 { |
| 36 | v.revert(); |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | let resource = self.resources.get_mut(key).unwrap(); |
| 41 | if let Ok(res) = resource.get() { |
| 42 | Some(res.clone()) |
| 43 | } else { |
| 44 | // FIXME: panic or throw err ? |
| 45 | None |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | pub(crate) fn append(&mut self, other: &mut StorageInner) { |
| 50 | for (k, v) in std::mem::take(&mut other.resources).into_iter() { |