aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/asset/renderer.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-14 00:14:30 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-14 00:14:30 +0800
commit1f2462ae53446c37c6cfe53a57ea86f695c4ef0a (patch)
tree9d54a4dcbaf1dc6fe36ecaf98253cbc521ddc8b0 /mingling_core/src/asset/renderer.rs
parent47aa95b2c65473950e089beac6ac986a3240608e (diff)
docs: expand trait and type documentation with examples
Diffstat (limited to 'mingling_core/src/asset/renderer.rs')
-rw-r--r--mingling_core/src/asset/renderer.rs31
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;
}