Skip to content

Commit b9e37dd

Browse files
joseph-gioItsDoot
authored andcommitted
Add a const PipeSystem constructor (bevyengine#7019)
# Objective Fix bevyengine#5914. `PipeSystem` cannot be constructed in `const` contexts. ## Solution Add a const `PipeSystem::new` function.
1 parent 3b7312b commit b9e37dd

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

crates/bevy_ecs/src/query/access.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,21 @@ impl<T: SparseSetIndex + fmt::Debug> fmt::Debug for Access<T> {
7171
}
7272
impl<T: SparseSetIndex> Default for Access<T> {
7373
fn default() -> Self {
74+
Self::new()
75+
}
76+
}
77+
78+
impl<T: SparseSetIndex> Access<T> {
79+
/// Creates an empty [`Access`] collection.
80+
pub const fn new() -> Self {
7481
Self {
7582
reads_all: false,
76-
reads_and_writes: Default::default(),
77-
writes: Default::default(),
83+
reads_and_writes: FixedBitSet::new(),
84+
writes: FixedBitSet::new(),
7885
marker: PhantomData,
7986
}
8087
}
81-
}
8288

83-
impl<T: SparseSetIndex> Access<T> {
8489
/// Increases the set capacity to the specified amount.
8590
///
8691
/// Does nothing if `capacity` is less than or equal to the current value.

crates/bevy_ecs/src/system/system_piping.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ pub struct PipeSystem<SystemA, SystemB> {
5454
archetype_component_access: Access<ArchetypeComponentId>,
5555
}
5656

57+
impl<SystemA, SystemB> PipeSystem<SystemA, SystemB> {
58+
/// Manual constructor for creating a [`PipeSystem`].
59+
/// This should only be used when [`IntoPipeSystem::pipe`] cannot be used,
60+
/// such as in `const` contexts.
61+
pub const fn new(system_a: SystemA, system_b: SystemB, name: Cow<'static, str>) -> Self {
62+
Self {
63+
system_a,
64+
system_b,
65+
name,
66+
component_access: Access::new(),
67+
archetype_component_access: Access::new(),
68+
}
69+
}
70+
}
71+
5772
impl<SystemA: System, SystemB: System<In = SystemA::Out>> System for PipeSystem<SystemA, SystemB> {
5873
type In = SystemA::In;
5974
type Out = SystemB::Out;
@@ -154,13 +169,8 @@ where
154169
fn pipe(self, system: SystemB) -> PipeSystem<SystemA::System, SystemB::System> {
155170
let system_a = IntoSystem::into_system(self);
156171
let system_b = IntoSystem::into_system(system);
157-
PipeSystem {
158-
name: Cow::Owned(format!("Pipe({}, {})", system_a.name(), system_b.name())),
159-
system_a,
160-
system_b,
161-
archetype_component_access: Default::default(),
162-
component_access: Default::default(),
163-
}
172+
let name = format!("Pipe({}, {})", system_a.name(), system_b.name());
173+
PipeSystem::new(system_a, system_b, Cow::Owned(name))
164174
}
165175
}
166176

0 commit comments

Comments
 (0)