55// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
66// option. This file may not be copied, modified, or distributed
77// except according to those terms.
8-
98use core:: num:: NonZeroU32 ;
109use core:: convert:: From ;
1110use core:: fmt;
12- #[ cfg( not( target_env = "sgx" ) ) ]
13- use std:: { io, error} ;
1411
1512// A randomly-chosen 24-bit prefix for our codes
1613pub ( crate ) const CODE_PREFIX : u32 = 0x57f4c500 ;
@@ -21,7 +18,7 @@ const CODE_UNAVAILABLE: u32 = CODE_PREFIX | 0x01;
2118///
2219/// This type is small and no-std compatible.
2320#[ derive( Copy , Clone , Eq , PartialEq ) ]
24- pub struct Error ( NonZeroU32 ) ;
21+ pub struct Error ( pub ( crate ) NonZeroU32 ) ;
2522
2623impl Error {
2724 /// An unknown error.
@@ -44,7 +41,7 @@ impl Error {
4441 self . 0
4542 }
4643
47- fn msg ( & self ) -> Option < & ' static str > {
44+ pub ( crate ) fn msg ( & self ) -> Option < & ' static str > {
4845 if let Some ( msg) = super :: error_msg_inner ( self . 0 ) {
4946 Some ( msg)
5047 } else {
@@ -81,33 +78,9 @@ impl From<NonZeroU32> for Error {
8178 }
8279}
8380
84- #[ cfg( not( target_env = "sgx" ) ) ]
85- impl From < io:: Error > for Error {
86- fn from ( err : io:: Error ) -> Self {
87- err. raw_os_error ( )
88- . and_then ( |code| NonZeroU32 :: new ( code as u32 ) )
89- . map ( |code| Error ( code) )
90- // in practice this should never happen
91- . unwrap_or ( Error :: UNKNOWN )
92- }
93- }
94-
95- #[ cfg( not( target_env = "sgx" ) ) ]
96- impl From < Error > for io:: Error {
97- fn from ( err : Error ) -> Self {
98- match err. msg ( ) {
99- Some ( msg) => io:: Error :: new ( io:: ErrorKind :: Other , msg) ,
100- None => io:: Error :: from_raw_os_error ( err. 0 . get ( ) as i32 ) ,
101- }
102- }
103- }
104-
105- #[ cfg( not( target_env = "sgx" ) ) ]
106- impl error:: Error for Error { }
107-
10881#[ cfg( test) ]
10982mod tests {
110- use std :: mem:: size_of;
83+ use core :: mem:: size_of;
11184 use super :: Error ;
11285
11386 #[ test]
0 commit comments