1- use std:: ffi:: { CStr , CString } ;
1+ use alloc:: ffi:: CString ;
2+ use core:: ffi:: CStr ;
23
34/// A `dlerror` error.
45pub struct DlDescription ( pub ( crate ) CString ) ;
56
6- impl std :: fmt:: Debug for DlDescription {
7- fn fmt ( & self , f : & mut std :: fmt:: Formatter ) -> std :: fmt:: Result {
8- std :: fmt:: Debug :: fmt ( & self . 0 , f)
7+ impl core :: fmt:: Debug for DlDescription {
8+ fn fmt ( & self , f : & mut core :: fmt:: Formatter ) -> core :: fmt:: Result {
9+ core :: fmt:: Debug :: fmt ( & self . 0 , f)
910 }
1011}
1112
@@ -16,11 +17,15 @@ impl From<&CStr> for DlDescription {
1617}
1718
1819/// A Windows API error.
20+ #[ cfg( not( feature = "std" ) ) ]
21+ pub struct WindowsError ( pub ( crate ) i32 ) ;
22+
23+ #[ cfg( feature = "std" ) ]
1924pub struct WindowsError ( pub ( crate ) std:: io:: Error ) ;
2025
21- impl std :: fmt:: Debug for WindowsError {
22- fn fmt ( & self , f : & mut std :: fmt:: Formatter ) -> std :: fmt:: Result {
23- std :: fmt:: Debug :: fmt ( & self . 0 , f)
26+ impl core :: fmt:: Debug for WindowsError {
27+ fn fmt ( & self , f : & mut core :: fmt:: Formatter ) -> core :: fmt:: Result {
28+ core :: fmt:: Debug :: fmt ( & self . 0 , f)
2429 }
2530}
2631
@@ -82,17 +87,28 @@ pub enum Error {
8287 /// Could not create a new CString.
8388 CreateCString {
8489 /// The source error.
85- source : std :: ffi:: NulError ,
90+ source : alloc :: ffi:: NulError ,
8691 } ,
8792 /// Could not create a new CString from bytes with trailing null.
8893 CreateCStringWithTrailing {
8994 /// The source error.
90- source : std :: ffi:: FromBytesWithNulError ,
95+ source : core :: ffi:: FromBytesWithNulError ,
9196 } ,
9297}
9398
94- impl std:: error:: Error for Error {
95- fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
99+ impl core:: error:: Error for Error {
100+ #[ cfg( not( feature = "std" ) ) ]
101+ fn source ( & self ) -> Option < & ( dyn core:: error:: Error + ' static ) > {
102+ use Error :: * ;
103+ match * self {
104+ CreateCString { ref source } => Some ( source) ,
105+ CreateCStringWithTrailing { ref source } => Some ( source) ,
106+ _ => None ,
107+ }
108+ }
109+
110+ #[ cfg( feature = "std" ) ]
111+ fn source ( & self ) -> Option < & ( dyn core:: error:: Error + ' static ) > {
96112 use Error :: * ;
97113 match * self {
98114 CreateCString { ref source } => Some ( source) ,
@@ -106,8 +122,8 @@ impl std::error::Error for Error {
106122 }
107123}
108124
109- impl std :: fmt:: Display for Error {
110- fn fmt ( & self , f : & mut std :: fmt:: Formatter ) -> std :: fmt:: Result {
125+ impl core :: fmt:: Display for Error {
126+ fn fmt ( & self , f : & mut core :: fmt:: Formatter ) -> core :: fmt:: Result {
111127 use Error :: * ;
112128 match * self {
113129 DlOpen { ref desc } => write ! ( f, "{}" , desc. 0 . to_string_lossy( ) ) ,
0 commit comments