Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumRustCow clone-on-writeSingle-choice MCQ

What does this function return for the input `"hello world"`, and does it allocate a new `String`?

use std::borrow::Cow; fn sanitize(input: &str) -> Cow<str> { if input.contains(' ') { Cow::Owned(input.replace(' ', "_")) } else { Cow::Borrowed(input) } } // called as: sanitize("hello world")