1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
extern crate nsstring;
use nsstring::{nsCString, nsACString};
#[allow(non_camel_case_types)]
pub type nsresult = u32;
pub trait NsresultExt {
fn failed(self) -> bool;
fn succeeded(self) -> bool;
fn to_result(self) -> Result<nsresult, nsresult>;
fn error_name(self) -> nsCString;
}
impl NsresultExt for nsresult {
fn failed(self) -> bool {
(self >> 31) != 0
}
fn succeeded(self) -> bool {
!self.failed()
}
fn to_result(self) -> Result<nsresult, nsresult> {
if self.failed() {
Err(self)
} else {
Ok(self)
}
}
fn error_name(self) -> nsCString {
let mut cstr = nsCString::new();
unsafe {
Gecko_GetErrorName(self, &mut *cstr);
}
cstr
}
}
extern "C" {
fn Gecko_GetErrorName(rv: nsresult, cstr: *mut nsACString);
}
mod error_list {
include!(concat!(env!("MOZ_TOPOBJDIR"), "/xpcom/base/error_list.rs"));
}
pub use error_list::*;