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

A function takes `Cow<'a, str>` and only sometimes needs to modify it. Given the code below, what does it print?

use std::borrow::Cow; fn process(input: &str) -> Cow<str> { if input.contains(' ') { Cow::Owned(input.replace(' ', "_")) } else { Cow::Borrowed(input) } } fn main() { let a = process("hello world"); let b = process("hello"); println!("{} {}", matches!(a, Cow::Owned(_)), matches!(b, Cow::Owned(_))); }