Consider the following:
pub struct Foo {
x: Rc<Blah>
}
Now, if the x
field is never read, we will get a warning.
===
Now, I have this use case as follows:
pub struct Manager {
parts: Vec<Weak<Blah>>
}
pub struct Foo {
x: Rc<Blah>
}
impl Foo {
pub fn new(m: &mut Manager) -> Foo
let x: Rc<Blah> = ...;
m.parts.push(Rc::downgrade(x));
Foo { x }
}
}
So here what is happening:
-
there is some other 'manager' that has a bunch of
Weak<Blah>
and runs some code on them for every iteration -
the sole job of the
Foo.x
is to just keep the object alive, while theFoo
is alive
Question: is this 'design pattern' described above (1) a code smell or (2) reasonable ? If (1), what should I be using instead ?