Skip to content

Commit aaacea3

Browse files
committed
Add UntypedSchemtic
1 parent 5d03a26 commit aaacea3

File tree

1 file changed

+49
-12
lines changed

1 file changed

+49
-12
lines changed

rfcs/64-schematics.md

+49-12
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,32 @@ 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 `set_inference` function.
303+
```rust
304+
fn set_inference(self, system: S) -> UntypedSchematic
305+
where
306+
S: IntoSchematicInference
307+
```
284308

309+
Finally you can add updates by using the `add_update` function.
310+
This will not replace any systems added previously by this method.
285311
```rust
286-
app.add_schematic(CloneSchematic::<Visibility>::default());
312+
fn add_udpate<S>(self, system: S) -> UntypedSchematic
313+
where
314+
S: IntoSchematicUpdate
287315
```
288316

289317
## Implementation strategy
@@ -305,9 +333,18 @@ app.add_schematic(CloneSchematic::<Visibility>::default());
305333
* `Schematic` is
306334
```rust
307335
struct Schematic<A> {
308-
conversion: Box<dyn SchematicConversion<A>>,
309-
inference: Option<Box<dyn SchematicInference<A>>>,
310-
update: Option<Box<dyn SchematicUpdate<A>>>,
336+
marker: PhantomMarker<A>,
337+
conversion: Box<dyn SchematicConversion<Component = A>>,
338+
inference: Option<Box<dyn SchematicInference<Component = A>>>,
339+
update: Option<Box<dyn SchematicUpdate<Component = A>>>,
340+
}
341+
```
342+
* `UntypedSchematic` is
343+
```rust
344+
struct UntypedSchematic {
345+
conversion: Vec<Box<dyn SchematicConversion>>,
346+
inference: Vec<Box<dyn SchematicInference>>,
347+
update: Vec<Box<dyn SchematicUpdate>>,
311348
}
312349
```
313350
* `SchematicConversion`, `SchematicInference` and `SchematicUpdate` are basically just `System` with a restriction on the parameters

0 commit comments

Comments
 (0)