use std::borrow::Cow;
// return the input untouched, or an edited owned copy
fn snake(s: &str) -> Cow<str> {
if s.contains(' ') {
Cow::Owned(s.replace(' ', "_"))
} else {
Cow::Borrowed(s)
}
}
fn main() {
println!("{}", snake("hello world"));
println!("{}", snake("ok"));
}allocate only when you must change it