I want to split a string by a separator only once and put it into a tuple. I tried doing
fn splitOnce(in_string: &str) -> (&str, &str) {
let mut splitter = in_string.split(':');
let first = splitter.next().unwrap();
let second = splitter.fold("".to_string(), |a, b| a + b);
(first, &second)
}
but I keep getting told that second
does not live long enough. I guess it's saying that because splitter
only exists inside the function block but I'm not really sure how to address that. How to I coerce second
into existing beyond the function block? Or is there a better way to split a string only once?