Hi I’m new to Rust.
Reading the source code of libloading crate, although I can’t fully understand the source code, It seems that it returns function pointer directly from dlsym() call and there is no function pointer caching mechanism when lib.get() is called.
See this link below:
And calling dlsym() many times is not good at performance.
What I want to do is write a wrapper struct that holds a hash map and libloading struct, And a function that caches any types of function pointer from dlsym() call to the hash map.
let lib_wrapper = LibWrapper::new("/path/to/library.so"); let some_function: fn(u32) -> u32 = lib_wrapper.get(b"some_function"); // It caches function pointer internally to the hash map. let some_function2: fn(u32, u32) = lib_wrapper.get(b"some_function2");
The problem is hash map part. How can I make an hash map that accepts any type of function pointers?(is it possible in Rust?)
It would be easy if i could use void pointer in the hash map like this:
let mut hash_map: HashMap<&str, *const void> = HashMap::new(); hash_map.insert("some_function", lib.get(b"some_function") as *const void);