Hi, I have seen some C++ apis which makes some curious things... like allow to call functions which do not always are supported, is not an issue but in some bindings and rust things is not ideal.
So the question here is that to handle that types of circumstances right, we would need to keep a track of which functions are called from a struct, a simple use case would be this:
struct Foo;
impl Foo {
fn f1(&self) {
todo!()
}
fn f2(&self) {
todo!()
}
fn f3(&self) {
todo!()
}
fn f4(&self) {
todo!()
}
}
fn main() {
let foo = Foo;
// We need to know here which functions will be used in this struct
let f_list = foo.functions_use_in_the_future();
assert_eq!(f_list, ["f1", "f2", "f3"]);
foo.f1();
a(&foo);
b(&foo);
}
fn a(x: &Foo) {
x.f2()
}
fn b(x: &Foo) {
c(x);
}
fn c(x: &Foo) {
x.f3();
}
One challenge here is the moment, we would need to know before each call, which functions will be called, in this case, we need to know right after the creation of foo
which functions will be called later...
I don't know if rust Macros can do a trick with this, I have not much experience with them either to know if this could be done.
Thx!