Using str and String interchangably
问题 Suppose I'm trying to do a fancy zero-copy parser in Rust using &str , but sometimes I need to modify the text (e.g. to implement variable substitution). I really want to do something like this: fn main() { let mut v: Vec<&str> = "Hello there $world!".split_whitespace().collect(); for t in v.iter_mut() { if (t.contains("$world")) { *t = &t.replace("$world", "Earth"); } } println!("{:?}", &v); } But of course the String returned by t.replace() doesn't live long enough. Is there a nice way