Get an Arc reference to a resource of a given type at a given index. Multiple immutable references can be borrowed at any given time.
(&self, key: u32)
| 68 | /// Get an Arc reference to a resource of a given type at a given index. Multiple |
| 69 | /// immutable references can be borrowed at any given time. |
| 70 | pub fn get<T: Any + Send + Sync + Sized>(&self, key: u32) -> Result<Arc<T>, Error> { |
| 71 | if let Some(r) = self.0.read().unwrap().map.get(&key).cloned() { |
| 72 | r.downcast::<T>() |
| 73 | .map_err(|_| Error::badf().context("element is a different type")) |
| 74 | } else { |
| 75 | Err(Error::badf().context("key not in table")) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /// Get a mutable reference to a resource of a given type at a given index. |
| 80 | /// Only one such reference can be borrowed at any given time. |
no test coverage detected