5
5
6
6
use std:: { borrow:: Cow , convert:: Infallible , error, ffi:: CStr , fmt, str} ;
7
7
8
- use crate :: { translate:: * , Quark } ;
8
+ use crate :: { self as glib , translate:: * , Quark } ;
9
9
10
- wrapper ! {
11
- // rustdoc-stripper-ignore-next
12
- /// A generic error capable of representing various error domains (types).
13
- #[ derive( PartialEq , Eq , PartialOrd , Ord , Hash ) ]
14
- #[ doc( alias = "GError" ) ]
15
- pub struct Error ( Boxed <ffi:: GError >) ;
16
-
17
- match fn {
18
- copy => |ptr| ffi:: g_error_copy( ptr) ,
19
- free => |ptr| ffi:: g_error_free( ptr) ,
20
- type_ => || ffi:: g_error_get_type( ) ,
21
- }
22
- }
10
+ // rustdoc-stripper-ignore-next
11
+ /// A generic error capable of representing various error domains (types).
12
+ #[ glib_macros:: wrapper(
13
+ copy = ffi:: g_error_copy,
14
+ free = ffi:: g_error_free,
15
+ type = ffi:: g_error_get_type,
16
+ ) ]
17
+ #[ derive( PartialEq , Eq , PartialOrd , Ord , Hash ) ]
18
+ #[ doc( alias = "GError" ) ]
19
+ pub struct Error ( Boxed < ffi:: GError > ) ;
23
20
24
21
unsafe impl Send for Error { }
25
22
unsafe impl Sync for Error { }
@@ -42,20 +39,20 @@ impl Error {
42
39
// rustdoc-stripper-ignore-next
43
40
/// Checks if the error domain matches `T`.
44
41
pub fn is < T : ErrorDomain > ( & self ) -> bool {
45
- self . inner . domain == T :: domain ( ) . into_glib ( )
42
+ self . 0 . domain == T :: domain ( ) . into_glib ( )
46
43
}
47
44
48
45
// rustdoc-stripper-ignore-next
49
46
/// Returns the error domain quark
50
47
pub fn domain ( & self ) -> Quark {
51
- unsafe { from_glib ( self . inner . domain ) }
48
+ unsafe { from_glib ( self . 0 . domain ) }
52
49
}
53
50
54
51
// rustdoc-stripper-ignore-next
55
52
/// Checks if the error matches the specified domain and error code.
56
53
#[ doc( alias = "g_error_matches" ) ]
57
54
pub fn matches < T : ErrorDomain > ( & self , err : T ) -> bool {
58
- self . is :: < T > ( ) && self . inner . code == err. code ( )
55
+ self . is :: < T > ( ) && self . 0 . code == err. code ( )
59
56
}
60
57
61
58
// rustdoc-stripper-ignore-next
@@ -77,7 +74,7 @@ impl Error {
77
74
/// ```
78
75
pub fn kind < T : ErrorDomain > ( & self ) -> Option < T > {
79
76
if self . is :: < T > ( ) {
80
- T :: from ( self . inner . code )
77
+ T :: from ( self . 0 . code )
81
78
} else {
82
79
None
83
80
}
@@ -90,7 +87,7 @@ impl Error {
90
87
/// trait, but you can use this method if you need to have the message as a `&str`.
91
88
pub fn message ( & self ) -> & str {
92
89
unsafe {
93
- let bytes = CStr :: from_ptr ( self . inner . message ) . to_bytes ( ) ;
90
+ let bytes = CStr :: from_ptr ( self . 0 . message ) . to_bytes ( ) ;
94
91
str:: from_utf8 ( bytes)
95
92
. unwrap_or_else ( |err| str:: from_utf8 ( & bytes[ ..err. valid_up_to ( ) ] ) . unwrap ( ) )
96
93
}
@@ -106,10 +103,8 @@ impl fmt::Display for Error {
106
103
impl fmt:: Debug for Error {
107
104
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
108
105
f. debug_struct ( "Error" )
109
- . field ( "domain" , unsafe {
110
- & crate :: Quark :: from_glib ( self . inner . domain )
111
- } )
112
- . field ( "code" , & self . inner . code )
106
+ . field ( "domain" , unsafe { & crate :: Quark :: from_glib ( self . 0 . domain ) } )
107
+ . field ( "code" , & self . 0 . code )
113
108
. field ( "message" , & self . message ( ) )
114
109
. finish ( )
115
110
}
0 commit comments