Cow, but owned?

Is there a type for wrapping a T, which provides Cow<'a, T>-like functionality without the lifetime parameter? I imagine it would be implemented as a Either<Rc<T>, Box<T>>, and you can get_mut it to turn it into the box variant, and clone it cheaply as long as you haven't called get_mut yet.

Note that Rc on its own already supports clone-on-write functionality with Rc::make_mut.


This is also mentioned in the documentation of Cow. I know this because I’ve added the remark myself. I’d be curious why you didn’t see that / where else you might have looked instead.

I actually recalled that something like Rc::make_mut existed and checked just after asking the question. :sweat_smile: I'm pretty sure I've already used it somewhere in my codebase already...

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.