@@ -85,23 +85,24 @@ impl core::fmt::Display for StatusCode {
85
85
}
86
86
}
87
87
88
- /// Quic error used in non-ffi code.
88
+ /// Quic status used in non-ffi code.
89
89
/// Internal representation matches the os platfrom type.
90
+ /// Used for all non-ffi error return and callback status code fields.
90
91
#[ derive( Clone ) ]
91
- pub struct Error ( pub QUIC_STATUS ) ;
92
+ pub struct Status ( pub QUIC_STATUS ) ;
92
93
93
- impl Error {
94
- /// Create an error from enum.
94
+ impl Status {
95
+ /// Create an status from enum.
95
96
pub fn new ( ec : StatusCode ) -> Self {
96
97
Self ( ec as QUIC_STATUS )
97
98
}
98
- /// Convert to error code if possible.
99
- pub fn try_as_error_code ( & self ) -> Result < StatusCode , & str > {
99
+ /// Convert to status code if possible.
100
+ pub fn try_as_status_code ( & self ) -> Result < StatusCode , & str > {
100
101
use std:: convert:: TryFrom ;
101
102
StatusCode :: try_from ( self . 0 as QUIC_STATUS )
102
103
}
103
104
104
- /// Convert from raw ffi error type.
105
+ /// Convert from raw ffi status type.
105
106
pub fn ok_from_raw ( ec : QUIC_STATUS ) -> Result < ( ) , Self > {
106
107
let e = Self ( ec) ;
107
108
if e. is_ok ( ) {
@@ -111,7 +112,7 @@ impl Error {
111
112
}
112
113
}
113
114
114
- /// Return Err if the error is considered a failure.
115
+ /// Return Err if the status is considered a failure.
115
116
/// Ok includes both "no error" and "pending" status codes.
116
117
pub fn is_ok ( & self ) -> bool {
117
118
// on windows it is signed.
@@ -123,25 +124,25 @@ impl Error {
123
124
}
124
125
}
125
126
126
- impl std:: error:: Error for Error { }
127
+ impl std:: error:: Error for Status { }
127
128
128
- impl From < QUIC_STATUS > for Error {
129
+ impl From < QUIC_STATUS > for Status {
129
130
fn from ( value : QUIC_STATUS ) -> Self {
130
131
Self ( value)
131
132
}
132
133
}
133
134
134
- impl From < StatusCode > for Error {
135
+ impl From < StatusCode > for Status {
135
136
fn from ( value : StatusCode ) -> Self {
136
137
Self :: new ( value)
137
138
}
138
139
}
139
140
140
141
/// The debug message is in the same format as error in windows crate.
141
- impl core:: fmt:: Debug for Error {
142
+ impl core:: fmt:: Debug for Status {
142
143
fn fmt ( & self , fmt : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
143
144
let mut debug = fmt. debug_struct ( "Error" ) ;
144
- let str_code = match self . try_as_error_code ( ) {
145
+ let str_code = match self . try_as_status_code ( ) {
145
146
Ok ( c) => Some ( c) ,
146
147
Err ( _) => None ,
147
148
} ;
@@ -155,9 +156,9 @@ impl core::fmt::Debug for Error {
155
156
}
156
157
157
158
/// The display message is in the same format as error in windows crate.
158
- impl core:: fmt:: Display for Error {
159
+ impl core:: fmt:: Display for Status {
159
160
fn fmt ( & self , fmt : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
160
- let str_code = match self . try_as_error_code ( ) {
161
+ let str_code = match self . try_as_status_code ( ) {
161
162
Ok ( c) => Some ( c) ,
162
163
Err ( _) => None ,
163
164
} ;
@@ -172,11 +173,11 @@ impl core::fmt::Display for Error {
172
173
mod tests {
173
174
use crate :: ffi:: QUIC_STATUS ;
174
175
175
- use super :: { Error , StatusCode } ;
176
+ use super :: { Status , StatusCode } ;
176
177
177
178
#[ test]
178
179
fn error_fmt_test ( ) {
179
- let err = Error :: new ( StatusCode :: QUIC_STATUS_ABORTED ) ;
180
+ let err = Status :: new ( StatusCode :: QUIC_STATUS_ABORTED ) ;
180
181
// message is platform dependent.
181
182
#[ cfg( target_os = "windows" ) ]
182
183
assert_eq ! ( format!( "{err}" ) , "QUIC_STATUS_ABORTED (0x80004004)" ) ;
@@ -185,14 +186,14 @@ mod tests {
185
186
format!( "{err:?}" ) ,
186
187
"Error { code: 0x80004004, message: QUIC_STATUS_ABORTED }"
187
188
) ;
188
- let ec = err. try_as_error_code ( ) . unwrap ( ) ;
189
+ let ec = err. try_as_status_code ( ) . unwrap ( ) ;
189
190
assert_eq ! ( format!( "{ec}" ) , "QUIC_STATUS_ABORTED" ) ;
190
191
}
191
192
192
193
#[ test]
193
194
fn error_ok_test ( ) {
194
- assert ! ( !Error :: new( StatusCode :: QUIC_STATUS_ABORTED ) . is_ok( ) ) ;
195
- assert ! ( Error :: new( StatusCode :: QUIC_STATUS_SUCCESS ) . is_ok( ) ) ;
196
- assert ! ( Error :: ok_from_raw( StatusCode :: QUIC_STATUS_PENDING as QUIC_STATUS ) . is_ok( ) ) ;
195
+ assert ! ( !Status :: new( StatusCode :: QUIC_STATUS_ABORTED ) . is_ok( ) ) ;
196
+ assert ! ( Status :: new( StatusCode :: QUIC_STATUS_SUCCESS ) . is_ok( ) ) ;
197
+ assert ! ( Status :: ok_from_raw( StatusCode :: QUIC_STATUS_PENDING as QUIC_STATUS ) . is_ok( ) ) ;
197
198
}
198
199
}
0 commit comments