blob: f6dcbd070cee71979d2923fca08069af0f3e6405 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
use crate::RenderResult;
/// 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 handled by the renderer, used to convert it into a render result
type Previous;
/// 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;
}
|