I have an "inner" type that can be transformed to a "public" type. I want to implement Drop
traits for both of these, but the crux is that once the public object has been created, the Drop
trait of the inner object should no longer run.
I.e.
struct Inner { }
impl Drop for Inner {
fn drop(&mut self) {
println!("Inner dropped!");
}
}
struct Public { /* conceptually an Inner object lives in here */ }
impl Drop for Public {
fn drop(&mut self) {
println!("Public dropped!");
}
}
When a Public
object is dropped, I only want it to print "Public dropped!".
There's a From<Inner> for Public
which transforms the Inner into a Public
, what I'm trying to accomplish is to disable the Drop
for the Inner
once this happens. I realize I can use a semaphore variable to do this, but I'm wondering if there's some other way to do it.
Will running ManuallyDrop::new(inner)
when constructing the Public
object do the trick?