Insert a new already type-erased resource into the store. If a resource with this `TypeID` already exists, then an error will be returned instead.
(
&mut self,
resource: Box<dyn Any + Send>,
type_id: TypeId,
)
| 1051 | impl ProcStore { |
| 1052 | pub fn with_capacity(capacity: usize) -> Self { |
| 1053 | let mut h = HashMap::default(); |
| 1054 | h.reserve(capacity); |
| 1055 | Self(h) |
| 1056 | } |
| 1057 | |
| 1058 | /// Insert a new resource into the store. |
| 1059 | /// |
| 1060 | /// If a resource with this `TypeID` already exists, then an error will |
| 1061 | /// be returned instead. |
| 1062 | pub fn insert<S: Send + 'static>(&mut self, resource: S) -> Result<(), S> { |
| 1063 | if let Entry::Vacant(e) = self.0.entry(TypeId::of::<S>()) { |
| 1064 | e.insert(Box::new(resource)); |
| 1065 | Ok(()) |
| 1066 | } else { |
| 1067 | Err(resource) |