Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
lorentz15183187d@jestdotty the docs describe what it does perfectly, and I knew about it for years, but I needed to have written the problem tens of times and then felt bad about it for weeks contemplating every other possible solution before I realized that Cow is what I need.
-
Demolishun35044187dWhat does it solve? An undo function maybe? I spend a bit of effort preventing my COW objects from copying unintentionally.
-
lorentz15183187d@Demolishun My understanding is that it's meant to potentially save an allocation when I can't guarantee that the code path will not need an allocation, by holding either a borrowed or an owned value.
At the moment this means that I can merge the definition for a message that's sent up the call stack which would best borrow all of its constituent parts, and the equivalent definition that's passed down the stack, which must be completely self-contained. -
lorentz15183187d@Demolishun if you want to deliberately hold onto older versions of an object a Cow might be a handy component, but it's not really required. Even with my newfound understanding of Cow, I'd prefer a simple approach with immutable refcounted data and unwrap_or_clone before mutations.
Related Rants
in a moment of enlightenment, I realized what problem Cow (copy-on-write smart pointer) actually solves.
Time to touch every file I guess
rant
so many redundant allocations!
moo
rust
cow