Add a const PipeSystem constructor (#7019)
# Objective Fix #5914. `PipeSystem` cannot be constructed in `const` contexts. ## Solution Add a const `PipeSystem::new` function.
This commit is contained in:
parent
a91f89db73
commit
48b4a45d82
@ -71,16 +71,21 @@ impl<T: SparseSetIndex + fmt::Debug> fmt::Debug for Access<T> {
|
|||||||
}
|
}
|
||||||
impl<T: SparseSetIndex> Default for Access<T> {
|
impl<T: SparseSetIndex> Default for Access<T> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self::new()
|
||||||
reads_all: false,
|
|
||||||
reads_and_writes: Default::default(),
|
|
||||||
writes: Default::default(),
|
|
||||||
marker: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: SparseSetIndex> Access<T> {
|
impl<T: SparseSetIndex> Access<T> {
|
||||||
|
/// Creates an empty [`Access`] collection.
|
||||||
|
pub const fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
reads_all: false,
|
||||||
|
reads_and_writes: FixedBitSet::new(),
|
||||||
|
writes: FixedBitSet::new(),
|
||||||
|
marker: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Increases the set capacity to the specified amount.
|
/// Increases the set capacity to the specified amount.
|
||||||
///
|
///
|
||||||
/// Does nothing if `capacity` is less than or equal to the current value.
|
/// Does nothing if `capacity` is less than or equal to the current value.
|
||||||
|
|||||||
@ -54,6 +54,21 @@ pub struct PipeSystem<SystemA, SystemB> {
|
|||||||
archetype_component_access: Access<ArchetypeComponentId>,
|
archetype_component_access: Access<ArchetypeComponentId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<SystemA, SystemB> PipeSystem<SystemA, SystemB> {
|
||||||
|
/// Manual constructor for creating a [`PipeSystem`].
|
||||||
|
/// This should only be used when [`IntoPipeSystem::pipe`] cannot be used,
|
||||||
|
/// such as in `const` contexts.
|
||||||
|
pub const fn new(system_a: SystemA, system_b: SystemB, name: Cow<'static, str>) -> Self {
|
||||||
|
Self {
|
||||||
|
system_a,
|
||||||
|
system_b,
|
||||||
|
name,
|
||||||
|
component_access: Access::new(),
|
||||||
|
archetype_component_access: Access::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<SystemA: System, SystemB: System<In = SystemA::Out>> System for PipeSystem<SystemA, SystemB> {
|
impl<SystemA: System, SystemB: System<In = SystemA::Out>> System for PipeSystem<SystemA, SystemB> {
|
||||||
type In = SystemA::In;
|
type In = SystemA::In;
|
||||||
type Out = SystemB::Out;
|
type Out = SystemB::Out;
|
||||||
@ -154,13 +169,8 @@ where
|
|||||||
fn pipe(self, system: SystemB) -> PipeSystem<SystemA::System, SystemB::System> {
|
fn pipe(self, system: SystemB) -> PipeSystem<SystemA::System, SystemB::System> {
|
||||||
let system_a = IntoSystem::into_system(self);
|
let system_a = IntoSystem::into_system(self);
|
||||||
let system_b = IntoSystem::into_system(system);
|
let system_b = IntoSystem::into_system(system);
|
||||||
PipeSystem {
|
let name = format!("Pipe({}, {})", system_a.name(), system_b.name());
|
||||||
name: Cow::Owned(format!("Pipe({}, {})", system_a.name(), system_b.name())),
|
PipeSystem::new(system_a, system_b, Cow::Owned(name))
|
||||||
system_a,
|
|
||||||
system_b,
|
|
||||||
archetype_component_access: Default::default(),
|
|
||||||
component_access: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user