format_many 1.0.0

Extended format_many! macro which allows formatting with variable number of argument inside one macro call
Documentation
//! ### format_many
//! 
//! This crate provides extended `format_many!`
//! macro which allows formatting with variable 
//! number of argument inside one macro call.
//! 
//! This macro implemented using `macro_rules!` thus
//! lightweight and IDE-friendly
//! 
//! ```rust
//! use format_many::format_many;
//! 
//! let text: String = format_many!(
//!     "Hello {}", "World"
//! );
//! 
//! let text: String = format_many!(
//!     "Hello {}", "World";
//!     "Numbers {}, {}", 10, 11;
//!     "String literal";
//!     "Format {:?}", [1, 2, 3]
//! );
//! ```
//! 
//! `format_many!` recieves a list of format strings with corresponding values
//! separated by **`;`**. Arguments in this inner lists are separated 
//! by **`,`**.
//! 
//! Each argument separated by **`;`** behaves like it's own `format!` call,
//! with compile-time checked number of arguments.

/// Creates `String` using runtime concatenation of `format!` invocations with
/// corectness checks at compile time.
/// 
/// - Note: Trailing `;` and `,` are not allowed.
/// 
/// ```rust
/// use format_many::format_many;
/// 
/// let text: String = format_many!(
///     "Hello {}", "World"
/// );
/// 
/// let text: String = format_many!(
///     "Hello {}", "World";
///     "Numbers {}, {}", 10, 11;
///     "String literal";
///     "Format {:?}", [1, 2, 3]
/// );
/// ```
/// 
/// `format_many!` recieves a list of format strings with corresponding values
/// separated by **`;`**. Arguments in this inner lists are separated 
/// by **`,`**.
/// 
/// Each argument separated by **`;`** behaves like it's own `format!` call,
/// with compile-time checked number of arguments.
#[macro_export]
macro_rules! format_many {
    ($($($arg:tt),*);*) => {{
        let mut string = ::std::string::String::new();
        $(
            string.push_str(&::std::format!($($arg),*));
        )*
        string
    }};
}

#[cfg(test)]
mod test {

    #[test]
    fn test() {

        let _text = format_many!("Hello");
        let _text = format_many!("Hello {}", 10);
        let _text = format_many!("Hello {} {}", 10, "World");
        let _text = format_many!("Hello {} {}", 10, { String::from("World") });
        
        let _text = format_many!(
            "Hello {} {}", 10, "World";
            "Hello {}", "World"
        );
    }
}