I'm porting a working semantic data model (for a language compiler) from JavaScript to Rust and symbol factory methods are getting not as expected. In JavaScript I've an instance method SymbolPool#createName()
and in Rust I've a static method SymbolPool::create_name()
, where the self
parameter has turned into a Rc
, consequently making the method static.
I need to do symbol.set_pool(self)
in my factory, but actually the Symbol#set_pool()
method is going to take a Rc
.
I think that one workaround could be to store a _self_reference: Weak<SymbolPool>
field in SymbolPool
. However, the symbol factory methods are not the only issue. I had also to move some methods from Symbol
to SymbolPool
, just to take a Rc
(and not cluster the Symbol
trait with static methods, since Rc<dyn Symbol>
is used in the code).
I think that allowing self parameter as a Rc would benefit this (pre-RFC).