aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros/src
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-21 03:46:06 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-21 03:46:06 +0800
commitc81485b6ae1ba80d658ad8e4482d384303b539ef (patch)
treea15814ec00eeb06c4cacd989de0e9460ea8a328c /mingling_macros/src
parent7a438e07514ffc6b58b843dd8e42fa4088b95e71 (diff)
feat(core)!: replace RenderResult with buffered output model
Remove `Deref<Target=str>` and `render_text:String` in favor of `render_buffer:Vec<(String, RenderResultMode)>` and an `immediate_output` flag. Add `RenderResultMode` enum, `r_eprint!`/`r_eprintln!` macros, and new buffer manipulation methods (`append_to_buffer`, `eprint`, etc.). Update `Display` to trim output and remove trailing newline. Migrate all callers and tests away from `Deref` usage.
Diffstat (limited to 'mingling_macros/src')
-rw-r--r--mingling_macros/src/func/r_print.rs8
-rw-r--r--mingling_macros/src/lib.rs66
2 files changed, 74 insertions, 0 deletions
diff --git a/mingling_macros/src/func/r_print.rs b/mingling_macros/src/func/r_print.rs
index e81b544..0f77b2b 100644
--- a/mingling_macros/src/func/r_print.rs
+++ b/mingling_macros/src/func/r_print.rs
@@ -60,3 +60,11 @@ pub(crate) fn r_println(input: TokenStream) -> TokenStream {
pub(crate) fn r_print(input: TokenStream) -> TokenStream {
expand_print(input, "print")
}
+
+pub(crate) fn r_eprintln(input: TokenStream) -> TokenStream {
+ expand_print(input, "eprintln")
+}
+
+pub(crate) fn r_eprint(input: TokenStream) -> TokenStream {
+ expand_print(input, "eprint")
+}
diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs
index 56ed999..5e7a40f 100644
--- a/mingling_macros/src/lib.rs
+++ b/mingling_macros/src/lib.rs
@@ -1412,6 +1412,72 @@ pub fn r_print(input: TokenStream) -> TokenStream {
func::r_print::r_print(input)
}
+/// Prints text to a `RenderResult` buffer (standard error style), with a trailing newline.
+///
+/// This macro works identically to `r_println!` but conceptually targets
+/// "error output" — it writes into a `RenderResult` buffer with a trailing newline.
+///
+/// # Implicit buffer (inside `#[buffer]` functions)
+///
+/// ```rust,ignore
+/// use mingling::macros::{buffer, r_eprintln};
+///
+/// #[buffer]
+/// fn render() {
+/// r_eprintln!("Error: {}", err_msg);
+/// }
+/// ```
+///
+/// # Explicit buffer
+///
+/// Pass a `RenderResult` variable as the first argument:
+///
+/// ```rust,ignore
+/// use mingling::macros::r_eprintln;
+/// use mingling::RenderResult;
+///
+/// let mut r = RenderResult::new();
+/// r_eprintln!(r, "error: {}", 42);
+/// assert_eq!(&*r, "error: 42\n");
+/// ```
+#[proc_macro]
+pub fn r_eprintln(input: TokenStream) -> TokenStream {
+ func::r_print::r_eprintln(input)
+}
+
+/// Prints text to a `RenderResult` buffer (standard error style), without a trailing newline.
+///
+/// This macro works identically to `r_print!` but conceptually targets
+/// "error output" — it writes into a `RenderResult` buffer without a trailing newline.
+///
+/// # Implicit buffer (inside `#[buffer]` functions)
+///
+/// ```rust,ignore
+/// use mingling::macros::{buffer, r_eprint};
+///
+/// #[buffer]
+/// fn render() {
+/// r_eprint!("Error: ");
+/// r_eprintln!("something went wrong");
+/// }
+/// ```
+///
+/// # Explicit buffer
+///
+/// ```rust,ignore
+/// use mingling::macros::r_eprint;
+/// use mingling::RenderResult;
+///
+/// let mut r = RenderResult::new();
+/// r_eprint!(r, "error: ");
+/// r_eprintln!(r, "42");
+/// assert_eq!(&*r, "error: 42\n");
+/// ```
+#[proc_macro]
+pub fn r_eprint(input: TokenStream) -> TokenStream {
+ func::r_print::r_eprint(input)
+}
+
/// Derive macro for automatically implementing the `Grouped` trait on a struct.
///
/// The `#[derive(Grouped)]` macro: