1-
2- use std:: ffi:: { c_void, CString } ;
31pub use crate :: interfaces:: * ;
2+ use std:: ffi:: { c_void, CString } ;
43
5- pub type CreateInterfaceFn = extern "system" fn (
6- pName : * const i8 ,
7- pReturnCode : * mut i32
8- ) -> * mut c_void ;
4+ pub type CreateInterfaceFn =
5+ extern "system" fn ( pName : * const i8 , pReturnCode : * mut i32 ) -> * mut c_void ;
96
107/// # Safety
118/// This function is unsafe to transmute the internal libloading symbol to a proper createinterface function pointer.
129pub unsafe fn get_interface_handle ( file : & str ) -> Result < CreateInterfaceFn , libloading:: Error > {
1310 let lib = libloading:: Library :: new ( file) ?;
1411 let sym: libloading:: Symbol < CreateInterfaceFn > = lib. get ( b"CreateInterface\0 " ) ?;
1512
16- Ok ( std:: mem:: transmute ( sym) )
13+ Ok ( std:: mem:: transmute ( sym) )
1714}
1815
1916#[ derive( Debug ) ]
2017pub enum InterfaceError {
21- BadCString ( std:: ffi:: NulError ) ,
18+ BadCString ( std:: ffi:: NulError ) ,
2219 FactoryNotFound ,
2320}
2421
25- pub fn get_from_interface ( iface : & str , factory : CreateInterfaceFn ) -> Result < * mut ( ) , InterfaceError > {
22+ pub fn get_from_interface (
23+ iface : & str ,
24+ factory : CreateInterfaceFn ,
25+ ) -> Result < * mut ( ) , InterfaceError > {
2626 let mut status = 0 ;
2727
28- let iface = CString :: new ( iface)
29- . map_err ( InterfaceError :: BadCString ) ?;
28+ let iface = CString :: new ( iface) . map_err ( InterfaceError :: BadCString ) ?;
3029
31- let result = factory ( iface. as_ptr ( ) , & mut status ) ;
30+ let result = factory ( iface. as_ptr ( ) , & mut status) ;
3231
3332 if status == 0 && !result. is_null ( ) {
3433 Ok ( result as * mut ( ) )
3534 } else {
36- Err ( InterfaceError :: FactoryNotFound )
35+ Err ( InterfaceError :: FactoryNotFound )
3736 }
38- }
37+ }
0 commit comments