Skip to content

Commit 762a09a

Browse files
committed
fix combinators
1 parent 91427ae commit 762a09a

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

crates/bevy_ecs/src/schedule/condition.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,15 @@ where
11731173
a: impl FnOnce(SystemIn<'_, A>) -> Result<A::Out, RunSystemError>,
11741174
b: impl FnOnce(SystemIn<'_, A>) -> Result<B::Out, RunSystemError>,
11751175
) -> Result<Self::Out, RunSystemError> {
1176-
Ok(!(a(input)? && b(input)?))
1176+
match a(input) {
1177+
// short circuit because `a` && `b` short circuits if `a` is false
1178+
Ok(false) | Err(_) => Ok(true),
1179+
Ok(true) => match b(input) {
1180+
Ok(b) => Ok(!b),
1181+
// if `b` fails, we yield `true`
1182+
Err(_) => Ok(true),
1183+
},
1184+
}
11771185
}
11781186
}
11791187

@@ -1194,7 +1202,19 @@ where
11941202
a: impl FnOnce(SystemIn<'_, A>) -> Result<A::Out, RunSystemError>,
11951203
b: impl FnOnce(SystemIn<'_, A>) -> Result<B::Out, RunSystemError>,
11961204
) -> Result<Self::Out, RunSystemError> {
1197-
<OrMarker as Combine<A, B>>::combine(input, a, b).map(|result| !result)
1205+
// `a` might fail to validate against the current world, but if it
1206+
// fails, we still want to try running `b`.
1207+
// !(`a` || `b`)
1208+
match a(input) {
1209+
Ok(true) => Ok(false),
1210+
// a is `(Ok(false) | Err(_))`
1211+
a => match (a, b(input)) {
1212+
(_, Ok(false) | Err(_)) => Ok(true),
1213+
// propagate error
1214+
(Err(e), _) => Err(e),
1215+
(_, Ok(true)) => Ok(false),
1216+
},
1217+
}
11981218
}
11991219
}
12001220

@@ -1218,6 +1238,7 @@ where
12181238
// `a` might fail to validate against the current world, but if it
12191239
// fails, we still want to try running `b`.
12201240
match a(input) {
1241+
// short circuit if `a` is true
12211242
Ok(true) => Ok(true),
12221243
_ => b(input),
12231244
}
@@ -1241,7 +1262,20 @@ where
12411262
a: impl FnOnce(SystemIn<'_, A>) -> Result<A::Out, RunSystemError>,
12421263
b: impl FnOnce(SystemIn<'_, A>) -> Result<B::Out, RunSystemError>,
12431264
) -> Result<Self::Out, RunSystemError> {
1244-
<XorMarker as Combine<A, B>>::combine(input, a, b).map(|result| !result)
1265+
// even if `a` fails to validate, `b` might succeed
1266+
match (a(input), b(input)) {
1267+
(Err(_), Err(_)) => Ok(true),
1268+
(Err(e), Ok(v)) | (Ok(v), Err(e)) => {
1269+
if !v {
1270+
// !(`false` ^ `false`) == true
1271+
Ok(true)
1272+
} else {
1273+
// !(`false` ^ `true`) == `false`, but yield error
1274+
Err(e)
1275+
}
1276+
}
1277+
(Ok(a), Ok(b)) => Ok(!(a ^ b)),
1278+
}
12451279
}
12461280
}
12471281

0 commit comments

Comments
 (0)