MCPcopy Create free account
hub / github.com/BillyDM/Firewheel / insert_any

Method insert_any

crates/firewheel-core/src/node.rs:1053–1064  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

1051impl 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)

Callers

nothing calls this directly

Calls 2

entryMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected