aboutsummaryrefslogtreecommitdiff
path: root/mingling_core
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-20 08:42:16 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-20 08:42:16 +0800
commit7b3a1d7fd9f60b91a7f9602374c081882d46facc (patch)
treedc0c8a9bf095308e6d29091db4b5037c29ed5742 /mingling_core
parent9dc737acec1eab40ef65bef8e6c729a4e5e06401 (diff)
feat(macros): add `#[buffer]` attribute and re-export `r_print!(ln)`
macros Reintroduce `r_print!` and `r_println!` macros as public exports, now supporting both explicit buffer argument and implicit `#[buffer]` attr. Add `#[buffer]` attribute macro that wraps unit-returning functions to produce a `RenderResult` with an automatically injected buffer variable. Relax `RenderResult::print()` and `println()` to accept `impl AsRef<str>`.
Diffstat (limited to 'mingling_core')
-rw-r--r--mingling_core/src/renderer/render_result.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/mingling_core/src/renderer/render_result.rs b/mingling_core/src/renderer/render_result.rs
index e57a5b9..763f6fc 100644
--- a/mingling_core/src/renderer/render_result.rs
+++ b/mingling_core/src/renderer/render_result.rs
@@ -132,8 +132,8 @@ impl RenderResult {
/// result.print(", world!");
/// assert_eq!(result.deref(), "Hello, world!");
/// ```
- pub fn print(&mut self, text: &str) {
- self.render_text.push_str(text);
+ pub fn print(&mut self, text: impl AsRef<str>) {
+ self.render_text.push_str(text.as_ref());
}
/// Appends the given text followed by a newline to the rendered content.
@@ -149,8 +149,8 @@ impl RenderResult {
/// result.println("Second line");
/// assert_eq!(result.deref(), "First line\nSecond line\n");
/// ```
- pub fn println(&mut self, text: &str) {
- self.render_text.push_str(text);
+ pub fn println(&mut self, text: impl AsRef<str>) {
+ self.render_text.push_str(text.as_ref());
self.render_text.push('\n');
}