one more pass at the panic_like module
+use std::borrow::Cow;
+
use defmt_parser::Level;
use proc_macro::TokenStream;
use quote::quote;
@@ -6,22 +8,22 @@ use syn::parse_macro_input;
use crate::{construct, function_like::log};
pub(crate) fn expand(
- input: TokenStream,
- zero_args_string: &str,
- string_transform: impl FnOnce(&str) -> String,
+ args: TokenStream,
+ zero_args_format_string: &str,
+ transform_format_string: impl FnOnce(&str) -> String,
) -> TokenStream {
- let (format_string, formatting_args) = if input.is_empty() {
+ let (format_string, formatting_args) = if args.is_empty() {
// panic!() -> error!("panicked at 'explicit panic'")
- (construct::string_literal(zero_args_string), None)
+ (Cow::from(zero_args_format_string), None)
} else {
// panic!("a", b, c) -> error!("panicked at 'a'", b, c)
- let args = parse_macro_input!(input as log::Args);
- let format_string =
- construct::string_literal(&string_transform(&args.format_string.value()));
+ let log_args = parse_macro_input!(args as log::Args);
+ let format_string = transform_format_string(&log_args.format_string.value());
- (format_string, args.formatting_args)
+ (Cow::from(format_string), log_args.formatting_args)
};
+ let format_string = construct::string_literal(&format_string);
let log_stmt = log::expand_parsed(
Level::Error,
log::Args {
