rental is not for newcomer (or not for me? read its docs, read its example, read its test codes… understand little, and completely not know how to apply to my problem).
RefCell (I need to modify
Stream via reference in
CommonPart) have some overhead. I have to iterate through these Vec again and again intensively, hence I don’t want to give up performance here. I know that losing some performance is better than walking with bare feet into the dark wild. But I have another big reason as I mentioned in the original post:
How to tell Rust that
all_streams will always be there so that references in
common_parts will always valid?
Yes, when I know the fact that all references will always be valid why not go for some unsafe-Rust code. I decide to read some docs about unsafe-Rust (never read it before), and happy with my choice.
Some words for newcomers like me. If you are able to reason and sure about the safety of your piece of code, don’t be afraid of unsafe code. When you feel perfectly safe in an unsafe-block,
unsafe is your friend, otherwise just stay away from it.