@@ -2,7 +2,8 @@ use std::borrow::Cow;
2
2
use std:: ops:: Not ;
3
3
4
4
use crate :: system:: {
5
- Adapt , AdapterSystem , CombinatorSystem , Combine , IntoSystem , ReadOnlySystem , System ,
5
+ Adapt , AdapterSystem , CombinatorSystem , Combine , IntoSystem , ReadOnlySystem , System , SystemIn ,
6
+ SystemInput ,
6
7
} ;
7
8
8
9
/// A type-erased run condition stored in a [`Box`].
@@ -57,7 +58,7 @@ pub type BoxedCondition<In = ()> = Box<dyn ReadOnlySystem<In = In, Out = bool>>;
57
58
///
58
59
/// ```
59
60
/// # use bevy_ecs::prelude::*;
60
- /// fn identity() -> impl Condition<(), bool> {
61
+ /// fn identity() -> impl Condition<(), In< bool> > {
61
62
/// IntoSystem::into_system(|In(x)| x)
62
63
/// }
63
64
///
@@ -70,7 +71,7 @@ pub type BoxedCondition<In = ()> = Box<dyn ReadOnlySystem<In = In, Out = bool>>;
70
71
/// # world.insert_resource(DidRun(false));
71
72
/// # app.run(&mut world);
72
73
/// # assert!(world.resource::<DidRun>().0);
73
- pub trait Condition < Marker , In = ( ) > : sealed:: Condition < Marker , In > {
74
+ pub trait Condition < Marker , In : SystemInput = ( ) > : sealed:: Condition < Marker , In > {
74
75
/// Returns a new run condition that only returns `true`
75
76
/// if both this one and the passed `and` return `true`.
76
77
///
@@ -466,20 +467,20 @@ pub trait Condition<Marker, In = ()>: sealed::Condition<Marker, In> {
466
467
}
467
468
}
468
469
469
- impl < Marker , In , F > Condition < Marker , In > for F where F : sealed:: Condition < Marker , In > { }
470
+ impl < Marker , In : SystemInput , F > Condition < Marker , In > for F where F : sealed:: Condition < Marker , In > { }
470
471
471
472
mod sealed {
472
- use crate :: system:: { IntoSystem , ReadOnlySystem } ;
473
+ use crate :: system:: { IntoSystem , ReadOnlySystem , SystemInput } ;
473
474
474
- pub trait Condition < Marker , In > :
475
+ pub trait Condition < Marker , In : SystemInput > :
475
476
IntoSystem < In , bool , Marker , System = Self :: ReadOnlySystem >
476
477
{
477
478
// This associated type is necessary to let the compiler
478
479
// know that `Self::System` is `ReadOnlySystem`.
479
480
type ReadOnlySystem : ReadOnlySystem < In = In , Out = bool > ;
480
481
}
481
482
482
- impl < Marker , In , F > Condition < Marker , In > for F
483
+ impl < Marker , In : SystemInput , F > Condition < Marker , In > for F
483
484
where
484
485
F : IntoSystem < In , bool , Marker > ,
485
486
F :: System : ReadOnlySystem ,
@@ -496,7 +497,7 @@ pub mod common_conditions {
496
497
event:: { Event , EventReader } ,
497
498
prelude:: { Component , Query , With } ,
498
499
removal_detection:: RemovedComponents ,
499
- system:: { In , IntoSystem , Local , Res , Resource , System } ,
500
+ system:: { In , IntoSystem , Local , Res , Resource , System , SystemInput } ,
500
501
} ;
501
502
502
503
/// A [`Condition`]-satisfying system that returns `true`
@@ -1110,10 +1111,12 @@ pub mod common_conditions {
1110
1111
/// app.run(&mut world);
1111
1112
/// assert_eq!(world.resource::<Counter>().0, 2);
1112
1113
/// ```
1113
- pub fn condition_changed < Marker , CIn , C : Condition < Marker , CIn > > (
1114
- condition : C ,
1115
- ) -> impl Condition < ( ) , CIn > {
1116
- condition. pipe ( |In ( new) : In < bool > , mut prev : Local < bool > | -> bool {
1114
+ pub fn condition_changed < Marker , CIn , C > ( condition : C ) -> impl Condition < ( ) , CIn >
1115
+ where
1116
+ CIn : SystemInput ,
1117
+ C : Condition < Marker , CIn > ,
1118
+ {
1119
+ condition. pipe ( |In ( new) : In < bool > , mut prev : Local < bool > | {
1117
1120
let changed = * prev != new;
1118
1121
* prev = new;
1119
1122
changed
@@ -1164,10 +1167,11 @@ pub mod common_conditions {
1164
1167
/// app.run(&mut world);
1165
1168
/// assert_eq!(world.resource::<Counter>().0, 2);
1166
1169
/// ```
1167
- pub fn condition_changed_to < Marker , CIn , C : Condition < Marker , CIn > > (
1168
- to : bool ,
1169
- condition : C ,
1170
- ) -> impl Condition < ( ) , CIn > {
1170
+ pub fn condition_changed_to < Marker , CIn , C > ( to : bool , condition : C ) -> impl Condition < ( ) , CIn >
1171
+ where
1172
+ CIn : SystemInput ,
1173
+ C : Condition < Marker , CIn > ,
1174
+ {
1171
1175
condition. pipe ( move |In ( new) : In < bool > , mut prev : Local < bool > | -> bool {
1172
1176
let now_true = * prev != new && new == to;
1173
1177
* prev = new;
@@ -1179,21 +1183,22 @@ pub mod common_conditions {
1179
1183
/// Invokes [`Not`] with the output of another system.
1180
1184
///
1181
1185
/// See [`common_conditions::not`] for examples.
1182
- pub type NotSystem < T > = AdapterSystem < NotMarker , T > ;
1186
+ pub type NotSystem < S > = AdapterSystem < NotMarker , S > ;
1183
1187
1184
1188
/// Used with [`AdapterSystem`] to negate the output of a system via the [`Not`] operator.
1185
1189
#[ doc( hidden) ]
1186
1190
#[ derive( Clone , Copy ) ]
1187
1191
pub struct NotMarker ;
1188
1192
1189
- impl < T : System > Adapt < T > for NotMarker
1190
- where
1191
- T :: Out : Not ,
1192
- {
1193
- type In = T :: In ;
1194
- type Out = <T :: Out as Not >:: Output ;
1193
+ impl < S : System < Out : Not > > Adapt < S > for NotMarker {
1194
+ type In = S :: In ;
1195
+ type Out = <S :: Out as Not >:: Output ;
1195
1196
1196
- fn adapt ( & mut self , input : Self :: In , run_system : impl FnOnce ( T :: In ) -> T :: Out ) -> Self :: Out {
1197
+ fn adapt (
1198
+ & mut self ,
1199
+ input : <Self :: In as SystemInput >:: Inner < ' _ > ,
1200
+ run_system : impl FnOnce ( SystemIn < ' _ , S > ) -> S :: Out ,
1201
+ ) -> Self :: Out {
1197
1202
!run_system ( input)
1198
1203
}
1199
1204
}
@@ -1221,17 +1226,17 @@ pub struct AndMarker;
1221
1226
1222
1227
impl < In , A , B > Combine < A , B > for AndMarker
1223
1228
where
1224
- In : Copy ,
1229
+ for < ' a > In : SystemInput < Inner < ' a > : Copy > ,
1225
1230
A : System < In = In , Out = bool > ,
1226
1231
B : System < In = In , Out = bool > ,
1227
1232
{
1228
1233
type In = In ;
1229
1234
type Out = bool ;
1230
1235
1231
1236
fn combine (
1232
- input : Self :: In ,
1233
- a : impl FnOnce ( < A as System > :: In ) -> < A as System > :: Out ,
1234
- b : impl FnOnce ( < B as System > :: In ) -> < B as System > :: Out ,
1237
+ input : < Self :: In as SystemInput > :: Inner < ' _ > ,
1238
+ a : impl FnOnce ( SystemIn < ' _ , A > ) -> A :: Out ,
1239
+ b : impl FnOnce ( SystemIn < ' _ , A > ) -> B :: Out ,
1235
1240
) -> Self :: Out {
1236
1241
a ( input) && b ( input)
1237
1242
}
@@ -1242,17 +1247,17 @@ pub struct NandMarker;
1242
1247
1243
1248
impl < In , A , B > Combine < A , B > for NandMarker
1244
1249
where
1245
- In : Copy ,
1250
+ for < ' a > In : SystemInput < Inner < ' a > : Copy > ,
1246
1251
A : System < In = In , Out = bool > ,
1247
1252
B : System < In = In , Out = bool > ,
1248
1253
{
1249
1254
type In = In ;
1250
1255
type Out = bool ;
1251
1256
1252
1257
fn combine (
1253
- input : Self :: In ,
1254
- a : impl FnOnce ( < A as System > :: In ) -> < A as System > :: Out ,
1255
- b : impl FnOnce ( < B as System > :: In ) -> < B as System > :: Out ,
1258
+ input : < Self :: In as SystemInput > :: Inner < ' _ > ,
1259
+ a : impl FnOnce ( SystemIn < ' _ , A > ) -> A :: Out ,
1260
+ b : impl FnOnce ( SystemIn < ' _ , B > ) -> B :: Out ,
1256
1261
) -> Self :: Out {
1257
1262
!( a ( input) && b ( input) )
1258
1263
}
@@ -1263,17 +1268,17 @@ pub struct NorMarker;
1263
1268
1264
1269
impl < In , A , B > Combine < A , B > for NorMarker
1265
1270
where
1266
- In : Copy ,
1271
+ for < ' a > In : SystemInput < Inner < ' a > : Copy > ,
1267
1272
A : System < In = In , Out = bool > ,
1268
1273
B : System < In = In , Out = bool > ,
1269
1274
{
1270
1275
type In = In ;
1271
1276
type Out = bool ;
1272
1277
1273
1278
fn combine (
1274
- input : Self :: In ,
1275
- a : impl FnOnce ( < A as System > :: In ) -> < A as System > :: Out ,
1276
- b : impl FnOnce ( < B as System > :: In ) -> < B as System > :: Out ,
1279
+ input : < Self :: In as SystemInput > :: Inner < ' _ > ,
1280
+ a : impl FnOnce ( SystemIn < ' _ , A > ) -> A :: Out ,
1281
+ b : impl FnOnce ( SystemIn < ' _ , B > ) -> B :: Out ,
1277
1282
) -> Self :: Out {
1278
1283
!( a ( input) || b ( input) )
1279
1284
}
@@ -1284,17 +1289,17 @@ pub struct OrMarker;
1284
1289
1285
1290
impl < In , A , B > Combine < A , B > for OrMarker
1286
1291
where
1287
- In : Copy ,
1292
+ for < ' a > In : SystemInput < Inner < ' a > : Copy > ,
1288
1293
A : System < In = In , Out = bool > ,
1289
1294
B : System < In = In , Out = bool > ,
1290
1295
{
1291
1296
type In = In ;
1292
1297
type Out = bool ;
1293
1298
1294
1299
fn combine (
1295
- input : Self :: In ,
1296
- a : impl FnOnce ( < A as System > :: In ) -> < A as System > :: Out ,
1297
- b : impl FnOnce ( < B as System > :: In ) -> < B as System > :: Out ,
1300
+ input : < Self :: In as SystemInput > :: Inner < ' _ > ,
1301
+ a : impl FnOnce ( SystemIn < ' _ , A > ) -> A :: Out ,
1302
+ b : impl FnOnce ( SystemIn < ' _ , B > ) -> B :: Out ,
1298
1303
) -> Self :: Out {
1299
1304
a ( input) || b ( input)
1300
1305
}
@@ -1305,17 +1310,17 @@ pub struct XnorMarker;
1305
1310
1306
1311
impl < In , A , B > Combine < A , B > for XnorMarker
1307
1312
where
1308
- In : Copy ,
1313
+ for < ' a > In : SystemInput < Inner < ' a > : Copy > ,
1309
1314
A : System < In = In , Out = bool > ,
1310
1315
B : System < In = In , Out = bool > ,
1311
1316
{
1312
1317
type In = In ;
1313
1318
type Out = bool ;
1314
1319
1315
1320
fn combine (
1316
- input : Self :: In ,
1317
- a : impl FnOnce ( < A as System > :: In ) -> < A as System > :: Out ,
1318
- b : impl FnOnce ( < B as System > :: In ) -> < B as System > :: Out ,
1321
+ input : < Self :: In as SystemInput > :: Inner < ' _ > ,
1322
+ a : impl FnOnce ( SystemIn < ' _ , A > ) -> A :: Out ,
1323
+ b : impl FnOnce ( SystemIn < ' _ , B > ) -> B :: Out ,
1319
1324
) -> Self :: Out {
1320
1325
!( a ( input) ^ b ( input) )
1321
1326
}
@@ -1326,17 +1331,17 @@ pub struct XorMarker;
1326
1331
1327
1332
impl < In , A , B > Combine < A , B > for XorMarker
1328
1333
where
1329
- In : Copy ,
1334
+ for < ' a > In : SystemInput < Inner < ' a > : Copy > ,
1330
1335
A : System < In = In , Out = bool > ,
1331
1336
B : System < In = In , Out = bool > ,
1332
1337
{
1333
1338
type In = In ;
1334
1339
type Out = bool ;
1335
1340
1336
1341
fn combine (
1337
- input : Self :: In ,
1338
- a : impl FnOnce ( < A as System > :: In ) -> < A as System > :: Out ,
1339
- b : impl FnOnce ( < B as System > :: In ) -> < B as System > :: Out ,
1342
+ input : < Self :: In as SystemInput > :: Inner < ' _ > ,
1343
+ a : impl FnOnce ( SystemIn < ' _ , A > ) -> A :: Out ,
1344
+ b : impl FnOnce ( SystemIn < ' _ , B > ) -> B :: Out ,
1340
1345
) -> Self :: Out {
1341
1346
a ( input) ^ b ( input)
1342
1347
}
0 commit comments