gen_alloc_message!() { /* proc-macro */ }Expand description
Generates an allocatable message with placeholders for arguments.
This macro creates an AllocMessage that can be used to format strings with
a fixed number of arguments. The placeholders in the message are denoted by
{0}, {1}, etc., which correspond to the arguments provided during formatting.
§Notes
- The number of placeholders in the message must match the number of arguments
specified in the
AllocMessagetype. - The macro supports using ident within the message string.
§Examples
use local_fmt::{gen_alloc_message, AllocMessage};
// Example with argument
{
let message: AllocMessage<1> = gen_alloc_message!("Hello! {0}");
let text = message.format(&["World!"]);
assert_eq!(text, "Hello! World!");
}
// Example with string placeholder
{
let hello: String = "Hello".to_string();
let message: AllocMessage<2> = gen_alloc_message!("{hello} {0} World! {1}");
let text = message.format(&["Beautiful", "Rust!"]);
assert_eq!(text, "Hello Beautiful World! Rust!");
}
// Example with duplicate arguments
{
let message: AllocMessage<1> = gen_alloc_message!("{0} World! {0}");
let text = message.format(&["Beautiful"]);
assert_eq!(text, "Beautiful World! Beautiful");
}