replace!() { /* proc-macro */ }
Expand description
Replaces all matches of a pattern with another string in a string literal.
Alternatively the third argument can be ignored and the macro will remove all matches of the pattern instead.
Examples
Basic usage:
use lit_mod::replace;
assert_eq!("this is new", replace!("this is old", "old", "new"));
assert_eq!("than an old", replace!("this is old", "is", "an"));
assert_eq!("this is", replace!("this is old", " old"));
When the pattern doesn’t match:
use lit_mod::replace;
assert_eq!(
"this is old",
replace!("this is old", "cookie monster", "little lamb")
);