diff options
Diffstat (limited to 'mingling_core/src/asset/renderer.rs')
| -rw-r--r-- | mingling_core/src/asset/renderer.rs | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/mingling_core/src/asset/renderer.rs b/mingling_core/src/asset/renderer.rs index 732f9b7..f6dcbd0 100644 --- a/mingling_core/src/asset/renderer.rs +++ b/mingling_core/src/asset/renderer.rs @@ -1,10 +1,35 @@ use crate::RenderResult; -/// Takes over a type (`Self::Previous`) and converts it to a [`RenderResult`](./struct.RenderResult.html) +/// Rendering logic for Mingling programs +/// +/// Add a rendering type for registered types in the Mingling program. When they are routed to `to_render()`, this renderer will be invoked to render them into the result output. +/// +/// # Manual impl +/// +/// Generally speaking, it is recommended to use the [`#[renderer]`](https://docs.rs/mingling/latest/mingling/macros/attr.renderer.html) macro instead. +/// If you need to implement this manually, please refer to the following example: +/// +/// ``` +/// # use mingling_core::Renderer; +/// # use mingling_core::RenderResult; +/// # struct MyRenderer; +/// # struct StateMyType; +/// +/// impl Renderer for MyRenderer { +/// type Previous = StateMyType; +/// +/// fn render(prev: Self::Previous) -> RenderResult { +/// // The specific rendering logic +/// # return mingling_core::RenderResult::default(); +/// } +/// } +/// ``` pub trait Renderer { - /// The previous type in the chain + /// The previous type handled by the renderer, used to convert it into a render result type Previous; - /// Process the previous value and write the result into the provided [`RenderResult`](./struct.RenderResult.html) + /// The rendering logic, which converts the `Previous` type into the corresponding [`RenderResult`] output + /// + /// When a program is routed to the type registered for this renderer, this method will be called to convert and render the previous type into the final result. fn render(p: Self::Previous) -> RenderResult; } |
