diff --git a/src/core/log/fmt.rs b/src/core/log/fmt.rs index 62944977..8766eb8d 100644 --- a/src/core/log/fmt.rs +++ b/src/core/log/fmt.rs @@ -5,7 +5,7 @@ use crate::Result; pub fn html(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()> where - S: Write, + S: Write + ?Sized, { let color = color::code_tag(level); let level = level.as_str().to_uppercase(); @@ -19,7 +19,7 @@ where pub fn markdown(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()> where - S: Write, + S: Write + ?Sized, { let level = level.as_str().to_uppercase(); writeln!(out, "`{level:>5}` `{span:^12}` `{msg}`")?; @@ -29,7 +29,7 @@ where pub fn markdown_table(out: &mut S, level: &Level, span: &str, msg: &str) -> Result<()> where - S: Write, + S: Write + ?Sized, { let level = level.as_str().to_uppercase(); writeln!(out, "| {level:>5} | {span:^12} | {msg} |")?; @@ -39,7 +39,7 @@ where pub fn markdown_table_head(out: &mut S) -> Result<()> where - S: Write, + S: Write + ?Sized, { write!(out, "| level | span | message |\n| ------: | :-----: | :------- |\n")?; diff --git a/src/core/utils/string.rs b/src/core/utils/string.rs index a597d198..85282b30 100644 --- a/src/core/utils/string.rs +++ b/src/core/utils/string.rs @@ -30,6 +30,16 @@ macro_rules! is_format { }; } +#[inline] +pub fn collect_stream(func: F) -> Result +where + F: FnOnce(&mut dyn std::fmt::Write) -> Result<()>, +{ + let mut out = String::new(); + func(&mut out)?; + Ok(out) +} + #[inline] #[must_use] pub fn camel_to_snake_string(s: &str) -> String {