repeat_str

Macro repeat_str 

Source
macro_rules! repeat_str {
    ($item:expr, $times:expr) => { ... };
    ($item:expr, $times:expr, $separator:expr) => { ... };
}
Expand description

A macro for concatenates a string expression item repeated times with an optional separator separator.

The macro provides two forms of invocation. The first form is a shorthand that defaults the separator to an empty string.

§Arguments

  • item: The string expression to be repeated.
  • times: The number of times to repeat the expression.
  • separator: An optional separator to insert between repetitions. Defaults to an empty string if not provided.

§Returns

A String consisting of item repeated times times, with separator inserted between each repetition if provided.

§Example

use macrors::repeat_str;

let repeat_str_1 = repeat_str!("A", 5);
assert_eq!("AAAAA", repeat_str_1);

let repeat_str_2 = repeat_str!("A", 5, ",");
assert_eq!("A,A,A,A,A", repeat_str_2);

let repeat_str_3 = repeat_str!(101, 5, ",");
assert_eq!("101,101,101,101,101", repeat_str_3);

@since 0.2.0