I want to create instances of Rust structs through C++. C++ has the main function and the Rust code is used as a library.
To achieve that, I need a way to store the instances in a list of some kind and return the index of the list to C++ so it works like a pointer to a Rust struct.
Rust does not support static members, so I cannot create a static rust_instances: std::vec::Vec = std::vec::Vec::new()
to hold the Rust structures.
What would be the best option here?
I've searched and found some workarounds that simulate a static element, but I'd like to know if there's a better way to solve this problem.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…