我正在使用Rust创建一个实体组件系统,并且希望能够为每个不同的Component
类型存储一个Vec
组件:
pub trait Component {}
struct ComponentList<T: Component> {
components: Vec<T>,
}
是否可能创建这些ComponentList
的集合?
struct ComponentManager {
component_lists: Vec<ComponentList<_>>, // This does not work
}
这旨在加快检索特定组件
类型的列表,因为所有特定类型的组件实例将位于同一个组件列表
中。
Component
(后者)的每个impl
,使用Vec<ComponentList<c>>
。 - EpicPotatostruct ComponentManager { component1: Component1, component2: Component2, ... }
- E net4