Hi. I have a Gc<T>
struct (garbage collected smart pointer) that needs a value and a garbage collector that it will belong to for being constructed. Something like this:
struct GarbageCollector { ... }
struct Gc<T> { ... }
impl<T> Gc<T> {
pub fn new(value: T, collector: &GarbageCollector) -> Self {}
}
I thought that converting a Box<T>
into a Gc<T>
would be reasonable, so I tried implementing the From<Box<T>>
for Gc<T>
. But I can't construct a Gc
without having the garbage collector. So the only way of solving this that I can think of is something like this:
impl<T: Trace> From<(Box<T>, &GarbageCollector)> for Gc<T> {
fn from(value: (Box<T>, &GarbageCollector)) -> Self {
...
}
}
Do you think that this solution is idiomatic? Would you suggest me to use a method like from_box(box: Box<T>, collector: GarbageCollector) -> Self
instead or is the above solution fine?