use rsfindlibs::generate_library_wrapper; use libloading::Library; use std::ffi::{c_char, c_int}; use std::ffi::CString; use std::sync::Arc; #[repr(C)] pub struct FdbHandle { _empty: [u8; 0], } generate_library_wrapper! { FDBlib { fn fdb_new_handle(fdb: *mut *mut FdbHandle) -> c_int; fn fdb_initialise() -> c_int; fn fdb_new_handle_from_yaml(fdb: *mut *mut FdbHandle, system_config: *const c_char, user_config: *const c_char) -> c_int; fn fdb_delete_handle(fdb: *mut FdbHandle); } } #[test] fn test_loading() -> Result<(), Box> { let libpath = rsfindlibs::find("fdb5", None).expect("FDB5 library not found"); println!("Library found at: {}", libpath); let lib = Library::new(&libpath).map_err(|e| { eprintln!("Failed to load library: {}", e); e })?; println!("Library loaded"); let lib_wrapper = FDBlib::load(lib)?; println!("Library wrapper loaded"); let config = r#" type: local engine: toc schema: ./tests/schema spaces: - handler: Default roots: - path: ./tests/root "#; let sys_cfg = CString::new(config).map_err(|_| "System Config contains null byte".to_string())?; let usr_cfg = CString::new("").map_err(|_| "User Config contains null byte".to_string())?; let mut fdb_handle: *mut FdbHandle = std::ptr::null_mut(); let result = unsafe { (lib_wrapper.fdb_new_handle_from_yaml)(&mut fdb_handle, sys_cfg.as_ptr(), usr_cfg.as_ptr()) }; if result != 0 { panic!("Failed to create FDB handle"); } let result = unsafe { (lib_wrapper.fdb_initialise)()}; if result != 0 { panic!("Failed to initialise FDB"); } unsafe { (lib_wrapper.fdb_delete_handle)(fdb_handle); } println!("Result: {}", result); Ok(()) }