browser_window_ffi/
err.rs1#![allow(non_snake_case)]
2#![allow(non_camel_case_types)]
3
4use std::error::Error;
5use std::ffi::CStr;
6use std::fmt;
7use std::os::raw::*;
8
9
10
11pub type bw_ErrCode = c_uint;
12pub type bw_ErrMsgFn = extern "C" fn( code: c_uint, data: *const c_void ) -> *mut c_char;
13
14
15
16
17#[repr(C)]
18#[derive(Clone,Copy,Debug)]
19pub struct bw_Err {
20 pub code: c_uint,
21 pub data: *const c_void,
22 pub alloc_message: bw_ErrMsgFn
23}
24unsafe impl Send for bw_Err {}
26
27
28
29impl Error for bw_Err {
30 fn source(&self) -> Option<&(dyn Error + 'static)> { None }
31}
32
33impl fmt::Display for bw_Err {
34
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36
37 unsafe {
38 let msg_ptr = (self.alloc_message)( self.code, self.data );
39 let cstr = CStr::from_ptr( msg_ptr );
40 write!(f, "{}", cstr.to_string_lossy().as_ref())
41 }
42 }
43}
44
45
46
47extern "C" {
48 pub fn bw_Err_free( err: *mut bw_Err );
49}