I'm face to a design problem I have hard time to solve.
I'm writing a lib which expose FFI C functions which will be called from a C app. Roughly:
#[no_mangle]
pub extern "C"
fn PluginStartup(usefull_infos) {
// startup code here, build all "objects" you need,
}
#[no_mangle]
pub extern "C"
fn PluginExecute(other_infos) {
// execution code here, use the objects created before
}
#[no_mangle]
pub extern "C"
fn PluginEnd() {
// end code here, free the objects
}
As you can see, there is no main()
.
As I can't have any null pointer, how am I supposed to build the stuff I need in PluginStartup()
, use it in PluginExecute()
and clean it in PluginEnd()
. Do I really need a Option
? This would mean I always have to do match bla { Some(bla), None }
or unwrap()
each time I use the main structures (90% of the code)? It's crazy no?
In C I would have a null pointer, do the allocation stuff in PluginStartup()
and free in PluginEnd()
. I know rust don't do this but from your advanced rust perspective, what would be the smartest way to handle my situation?
A big thanks in advance!