Skip to content

Commit 4b69240

Browse files
committed
Add UntypedSchemtic
1 parent 5d03a26 commit 4b69240

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

rfcs/64-schematics.md

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ The derived implementation contains conversions both direction as well as update
123123
* `alternative<C>(self, other: Schematic<C>) -> Schematic<Result<A, C>>`
124124
* `filter<F: Fn(&A) -> bool>(self, f: F) -> Schematic<A>`
125125

126+
### Adding schematics to your app
127+
128+
`Schematic`s can be added to the app using
129+
```rust
130+
app.add_schematic(AnimationState::default_schematic());
131+
```
132+
133+
Since with many components you want to just copy the same component from the schematic to the main world, a `CloneSchematic<A: Clone>` is provided.
134+
135+
```rust
136+
app.add_schematic(CloneSchematic::<Visibility>::default());
137+
```
138+
126139
### Creating `Schematic` manually
127140

128141
`Schematic<A>` can be constructed manually using the `new` function
@@ -132,16 +145,16 @@ where
132145
S: IntoSchematicConversion
133146
```
134147

135-
You can add conversion in the other direction by using the `add_inference` function
148+
You can add conversion in the other direction by using the `set_inference` function
136149
```rust
137-
fn add_inference<S>(self, system: S) -> Schematic<A>
150+
fn set_inference<S>(self, system: S) -> Schematic<A>
138151
where
139152
S: IntoSchematicInference<Component = A>
140153
```
141154

142-
Finally you can add updates by using the `add_update` function
155+
Finally you can add updates by using the `set_update` function
143156
```rust
144-
fn add_udpate<S>(self, system: S) -> Schematic<A>
157+
fn set_udpate<S>(self, system: S) -> Schematic<A>
145158
where
146159
S: IntoSchematicUpdate<Component = A>
147160
```
@@ -273,17 +286,33 @@ fn update_animation_state(
273286
}
274287
```
275288

276-
### Adding schematics to your app
289+
### `UntypedSchematic`
277290

278-
`Schematic`s can be added to the app using
291+
A `UntypedSchematic` is the same as a `Schematic` just without the type restriction.
292+
Usually it is safer to use the `Schematic` interface, but you might want to handle multiple schematic components within the same system.
293+
Not having an associated type means, that the `map`, `zip`, `alternative` and `filter` methods are not available for `UntypedSchematic`.
294+
295+
`UntypedSchematic` can be constructed manually using the `new` function
279296
```rust
280-
app.add_schematic(AnimationState::default_schematic());
297+
fn new<S>(system: S) -> UntypedSchematic
298+
where
299+
S: IntoSchematicConversion
281300
```
282301

283-
Since with many components you want to just copy the same component from the schematic to the main world, a `CloneSchematic<A: Clone>` is provided.
302+
You can add conversion in the other direction by using the `add_inference` function.
303+
This will not replace any systems added previously by this method.
304+
```rust
305+
fn add_inference(self, system: S) -> Schematic<A>
306+
where
307+
S: IntoSchematicInference
308+
```
284309

310+
Finally you can add updates by using the `add_update` function.
311+
This will not replace any systems added previously by this method.
285312
```rust
286-
app.add_schematic(CloneSchematic::<Visibility>::default());
313+
fn add_udpate<S>(self, system: S) -> Schematic<A>
314+
where
315+
S: IntoSchematicUpdate
287316
```
288317

289318
## Implementation strategy
@@ -305,9 +334,18 @@ app.add_schematic(CloneSchematic::<Visibility>::default());
305334
* `Schematic` is
306335
```rust
307336
struct Schematic<A> {
308-
conversion: Box<dyn SchematicConversion<A>>,
309-
inference: Option<Box<dyn SchematicInference<A>>>,
310-
update: Option<Box<dyn SchematicUpdate<A>>>,
337+
marker: PhantomMarker<A>,
338+
conversion: Box<dyn SchematicConversion<Component = A>>,
339+
inference: Option<Box<dyn SchematicInference<Component = A>>>,
340+
update: Option<Box<dyn SchematicUpdate<Component = A>>>,
341+
}
342+
```
343+
* `UntypedSchematic` is
344+
```rust
345+
struct UntypedSchematic {
346+
conversion: Vec<Box<dyn SchematicConversion>>,
347+
inference: Vec<Box<dyn SchematicInference>>,
348+
update: Vec<Box<dyn SchematicUpdate>>,
311349
}
312350
```
313351
* `SchematicConversion`, `SchematicInference` and `SchematicUpdate` are basically just `System` with a restriction on the parameters

0 commit comments

Comments
 (0)