|
| 1 | +--- |
| 2 | +title: The `Process` trait no longer has a single output. |
| 3 | +pull_requests: [] |
| 4 | +--- |
| 5 | + |
| 6 | +In previous versions, the `Process` trait had an associated type for the output loader, and took a |
| 7 | +`writer` argument. This is no longer the case (in order to support one-to-many asset processing). |
| 8 | +This change requires that users indicate whether they are using the "single" writer mode or the |
| 9 | +"multiple" writer mode. |
| 10 | + |
| 11 | +If your previous trait implementation of `Process` looked like this: |
| 12 | + |
| 13 | +```rust |
| 14 | +impl Process for MyThing { |
| 15 | + type Settings = MyThingSettings; |
| 16 | + type OutputLoader = SomeLoader; |
| 17 | + |
| 18 | + async fn process( |
| 19 | + &self, |
| 20 | + context: &mut ProcessContext<'_>, |
| 21 | + meta: AssetMeta<(), Self>, |
| 22 | + writer: &mut Writer, |
| 23 | + ) -> Result<SomeLoader::Settings, ProcessError> { |
| 24 | + // Write to `writer`, then return the meta file you want. |
| 25 | + let meta = todo!(); |
| 26 | + Ok(meta) |
| 27 | + } |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +Now it needs to look like: |
| 32 | + |
| 33 | +```rust |
| 34 | +impl Process for MyThing { |
| 35 | + type Settings = MyThingSettings; |
| 36 | + |
| 37 | + async fn process( |
| 38 | + &self, |
| 39 | + context: &mut ProcessContext<'_>, |
| 40 | + meta: AssetMeta<(), Self>, |
| 41 | + writer_context: WriteContext<'_>, |
| 42 | + ) -> Result<(), ProcessError> { |
| 43 | + let writer = writer_context.write_single().await?; |
| 44 | + // Write to `writer`, then return the meta file you want. |
| 45 | + let meta = todo!(); |
| 46 | + writer.finish(meta).await |
| 47 | + } |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +In addition, the returned `writer` is a wrapper around `&mut Writer`. This means you may need to |
| 52 | +explicitly dereference in order to pass this writer into functions that take a `&mut Writer`. |
| 53 | + |
| 54 | +This does not apply if you are using the `LoadTransformAndSave` process - existing uses should |
| 55 | +continue to work. |
0 commit comments