Manishearth / rust-gc

Simple tracing (mark and sweep) garbage collector for Rust
Mozilla Public License 2.0
962 stars 50 forks source link

Add trace for Cow #144

Closed kaleidawave closed 2 years ago

kaleidawave commented 2 years ago

Added trace and finalize implementation for std::borrow::Cow. I think I have done this correctly, where it only marks if it is the owned variant. Not particularly sure

Manishearth commented 2 years ago

Please make sure it builds.

kaleidawave commented 2 years ago

apologies was doing quickly using github.dev of which unfortunately doesn't have rust-analyzer built in, thought workflows were eagerly enabled and would catch. Have fixed syntax, so should be okay.

kaleidawave commented 2 years ago

Ooof, have fixed the guard and formatting. The tests pass locally now. This should be equivalent to the derived implementation on enum X<'a, T> { Owned(T), Reference(&'a T) } although it skips the branch with the reference variant as the implementation of Trace for references is already empty (could call it but that empty implementation isn't going to change so didn't see the point).

The use case is I have a struct X<'a>(Cow<'a, Y>). Most of the time I am only dealing with it as a reference but sometimes I need it for later and store a X<'static> in a object which can be cyclic under Y thus needing to doing the trace on the owned data.