pub fn register<T: Component>(&mut self)
where
T::Storage: Default,
{
self.register_with_storage::<_, T>(Default::default);
}
/// Registers a new component with a given storage.
///
/// Does nothing if the component was already registered.
pub fn register_with_storage<F, T>(&mut self, storage: F)
where
F: FnOnce() -> T::Storage,
T: Component,
{
Self::register_with_storage_internal::<F, T>(&mut self.res, storage);
}
/// Registers a new component with a given storage.
///
/// Does nothing if the component was already registered.
pub(crate) fn register_with_storage_internal<F, T>(res: &mut Resources, storage: F)
where
F: FnOnce() -> T::Storage,
T: Component,
{
res.entry()
.or_insert_with(move || MaskedStorage::<T>::new(storage()));
res.fetch_mut::<MetaTable<AnyStorage>>()
.register(&*res.fetch::<MaskedStorage<T>>());
}
In particular, in the above function definitions, how do we force it to use DenseVec ?
I'm not a specs user, but that's not what that method does - note the closure given to register_with_storage() must return T::Storage - so the world has no say in the type of it. So it's just a case of you, the caller, specifying the construction of the storage type, but the type must be the same as what the component specifies.