browser_window_core/
error.rs1use crate::prelude::*;
2
3use std::{
4 ffi::CStr,
5 fmt
6};
7
8
9
10#[derive(Debug)]
11pub struct CbwError (cbw_Err);
12
13
14pub type CbwResult<T> = Result<T, CbwError>;
15
16
17
18impl fmt::Display for CbwError {
19 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20 unsafe {
21 let c_msg = cbw_Err_message( &self.0 );
22
23 let result = write!(f, "[{}] {}", self.0.code, CStr::from_ptr(c_msg).to_str().expect("invalid utf-8 in bw_Err error message"));
24
25 cbw_string_freeCstr(c_msg);
26
27 return result;
28 }
29 }
30}
31
32impl std::error::Error for CbwError {
33 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
34}
35
36impl From<cbw_Err> for CbwError {
37 fn from(e: cbw_Err) -> Self {
38 Self (e)
39 }
40}