MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / get

Method get

flow-rs/src/resource/storage.rs:22–47  ·  view source on GitHub ↗
(&mut self, key: &(u64, String))

Source from the content-addressed store, hash-verified

20
21impl 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() {

Callers 1

storageFunction · 0.45

Calls 4

revertMethod · 0.80
viewMethod · 0.80
get_mutMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected