aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-11 14:44:17 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-11 14:44:17 +0800
commitc5736152b0adeef17349265c4b9277ba17b8bcfd (patch)
treea5a5227ef4ca20ec09d1c8cf0655e9f9f33e03b6 /mingling_core/src
parentc08b2d608abe134e37bc4dee7df2113fac968e06 (diff)
feat: require renderers to return RenderResult instead of mutating one
BREAKING CHANGE: The `render` method on `Renderer`, `HelpRequest`, and `ProgramCollect` now returns `RenderResult` instead of taking `&mut RenderResult`. The `r_print!` and `r_println!` macros have been removed in favor of using `std::io::Write` directly on `RenderResult`.
Diffstat (limited to 'mingling_core/src')
-rw-r--r--mingling_core/src/asset/help.rs2
-rw-r--r--mingling_core/src/asset/renderer.rs2
-rw-r--r--mingling_core/src/program/collection.rs6
-rw-r--r--mingling_core/src/program/collection/mock.rs6
-rw-r--r--mingling_core/src/program/exec.rs16
-rw-r--r--mingling_core/src/program/hook.rs4
6 files changed, 14 insertions, 22 deletions
diff --git a/mingling_core/src/asset/help.rs b/mingling_core/src/asset/help.rs
index ff2b3d4..b3742f2 100644
--- a/mingling_core/src/asset/help.rs
+++ b/mingling_core/src/asset/help.rs
@@ -6,5 +6,5 @@ pub trait HelpRequest {
type Entry;
/// Process the previous value and write the result into the provided [`RenderResult`](./struct.RenderResult.html)
- fn render_help(p: Self::Entry, r: &mut RenderResult);
+ fn render_help(p: Self::Entry) -> RenderResult;
}
diff --git a/mingling_core/src/asset/renderer.rs b/mingling_core/src/asset/renderer.rs
index 1d5a2c1..732f9b7 100644
--- a/mingling_core/src/asset/renderer.rs
+++ b/mingling_core/src/asset/renderer.rs
@@ -6,5 +6,5 @@ pub trait Renderer {
type Previous;
/// Process the previous value and write the result into the provided [`RenderResult`](./struct.RenderResult.html)
- fn render(p: Self::Previous, r: &mut RenderResult);
+ fn render(p: Self::Previous) -> RenderResult;
}
diff --git a/mingling_core/src/program/collection.rs b/mingling_core/src/program/collection.rs
index 044379c..cbb9363 100644
--- a/mingling_core/src/program/collection.rs
+++ b/mingling_core/src/program/collection.rs
@@ -7,7 +7,7 @@ use crate::Dispatcher;
use crate::{AnyOutput, ChainProcess, Groupped, RenderResult};
#[cfg(feature = "structural_renderer")]
-use crate::{StructuralRendererSetting, error::StructuralRendererSerializeError};
+use crate::{error::StructuralRendererSerializeError, StructuralRendererSetting};
#[cfg(feature = "comp")]
use crate::{ShellContext, Suggest};
@@ -53,10 +53,10 @@ pub trait ProgramCollect {
fn build_empty_result() -> AnyOutput<Self::Enum>;
/// Render the input [`AnyOutput`](./struct.AnyOutput.html)
- fn render(any: AnyOutput<Self::Enum>, r: &mut RenderResult);
+ fn render(any: AnyOutput<Self::Enum>) -> RenderResult;
/// Render help for Entry
- fn render_help(any: AnyOutput<Self::Enum>, r: &mut RenderResult);
+ fn render_help(any: AnyOutput<Self::Enum>) -> RenderResult;
/// Find a matching chain to continue execution based on the input [AnyOutput](./struct.AnyOutput.html), returning a new [AnyOutput](./struct.AnyOutput.html)
#[cfg(feature = "async")]
diff --git a/mingling_core/src/program/collection/mock.rs b/mingling_core/src/program/collection/mock.rs
index 568000a..20e6658 100644
--- a/mingling_core/src/program/collection/mock.rs
+++ b/mingling_core/src/program/collection/mock.rs
@@ -7,7 +7,7 @@ use crate::Dispatcher;
use crate::{AnyOutput, ChainProcess, Groupped, ProgramCollect, RenderResult};
#[cfg(feature = "structural_renderer")]
-use crate::{StructuralRendererSetting, error::StructuralRendererSerializeError};
+use crate::{error::StructuralRendererSerializeError, StructuralRendererSetting};
#[cfg(feature = "comp")]
use crate::{ShellContext, Suggest};
@@ -59,11 +59,11 @@ impl ProgramCollect for MockProgramCollect {
unreachable!()
}
- fn render(_any: AnyOutput<Self::Enum>, _r: &mut RenderResult) {
+ fn render(_any: AnyOutput<Self::Enum>) -> RenderResult {
unreachable!()
}
- fn render_help(_any: AnyOutput<Self::Enum>, _r: &mut RenderResult) {
+ fn render_help(_any: AnyOutput<Self::Enum>) -> RenderResult {
unreachable!()
}
diff --git a/mingling_core/src/program/exec.rs b/mingling_core/src/program/exec.rs
index d1983ed..3224c82 100644
--- a/mingling_core/src/program/exec.rs
+++ b/mingling_core/src/program/exec.rs
@@ -461,18 +461,14 @@ pub(crate) fn handle_program_control<C: ProgramCollect<Enum = C>>(
fn render<C: ProgramCollect<Enum = C>>(program: &Program<C>, any: AnyOutput<C>) -> RenderResult {
#[cfg(not(feature = "structural_renderer"))]
{
- let mut render_result = RenderResult::default();
- C::render(any, &mut render_result);
- render_result
+ C::render(any)
}
#[cfg(feature = "structural_renderer")]
{
#[allow(unreachable_patterns)]
match program.structural_renderer_name {
super::StructuralRendererSetting::Disable => {
- let mut render_result = RenderResult::default();
- C::render(any, &mut render_result);
- render_result
+ C::render(any)
}
_ => C::structural_render(any, &program.structural_renderer_name).unwrap(),
}
@@ -487,18 +483,14 @@ fn render_help<C: ProgramCollect<Enum = C>>(
) -> RenderResult {
#[cfg(not(feature = "structural_renderer"))]
{
- let mut render_result = RenderResult::default();
- C::render_help(entry, &mut render_result);
- render_result
+ C::render_help(entry)
}
#[cfg(feature = "structural_renderer")]
{
#[allow(unreachable_patterns)]
match program.structural_renderer_name {
super::StructuralRendererSetting::Disable => {
- let mut render_result = RenderResult::default();
- C::render_help(entry, &mut render_result);
- render_result
+ C::render_help(entry)
}
_ => RenderResult::default(),
}
diff --git a/mingling_core/src/program/hook.rs b/mingling_core/src/program/hook.rs
index 630baae..56d8e0e 100644
--- a/mingling_core/src/program/hook.rs
+++ b/mingling_core/src/program/hook.rs
@@ -718,11 +718,11 @@ mod tests {
unreachable!()
}
- fn render(_any: crate::AnyOutput<MockHookEnum>, _r: &mut crate::RenderResult) {
+ fn render(_any: crate::AnyOutput<MockHookEnum>) -> crate::RenderResult {
unreachable!()
}
- fn render_help(_any: crate::AnyOutput<MockHookEnum>, _r: &mut crate::RenderResult) {
+ fn render_help(_any: crate::AnyOutput<MockHookEnum>) -> crate::RenderResult {
unreachable!()
}