E.g.:
let path_to_lib_str =
path_to_lib
.as_ref()
.to_string_lossy();
let path_to_lib_c_str = path_to_lib_str.as_ptr() as *const c_char;
here path_to_lib_c_str is not really a c_str, but a pointer to a regular Rust utf8 string slice. The issue can be reproduced with something like this:
let name = "mylib.so123";
LibUnsafe::new(&name[0..8]).unwrap();
where mylib.so is a valid shared lib that can be located by dlopen.