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