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

You have a function returning `Cow<'static, str>`. In which case does this code allocate a new `String` on the heap, given the input?

fn normalize(s: &'static str) -> Cow<'static, str> { if s.contains(' ') { Cow::Owned(s.replace(' ', "_")) } else { Cow::Borrowed(s) } } let a = normalize("hello"); let b = normalize("hello world");