Skip to content

Commit 751aa43

Browse files
authored
Merge pull request #264 from Mr-Leshiy/fix-warnings
Remove deprecated usage of the "description" and "cause" functions
2 parents b78d08b + 5bf9f4f commit 751aa43

File tree

6 files changed

+63
-92
lines changed

6 files changed

+63
-92
lines changed

src/codec/http.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,15 @@ pub enum HttpCodecError {
220220

221221
impl Display for HttpCodecError {
222222
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
223-
fmt.write_str(self.description())
223+
match self {
224+
HttpCodecError::Io(e) => fmt.write_str(e.to_string().as_str()),
225+
HttpCodecError::Http(e) => fmt.write_str(e.to_string().as_str()),
226+
}
224227
}
225228
}
226229

227230
impl Error for HttpCodecError {
228-
fn description(&self) -> &str {
229-
match *self {
230-
HttpCodecError::Io(ref e) => e.description(),
231-
HttpCodecError::Http(ref e) => e.description(),
232-
}
233-
}
234-
235-
fn cause(&self) -> Option<&dyn Error> {
231+
fn source(&self) -> Option<&(dyn Error + 'static)> {
236232
match *self {
237233
HttpCodecError::Io(ref error) => Some(error),
238234
HttpCodecError::Http(ref error) => Some(error),

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ macro_rules! upsert_header {
6565
if $headers.has::<$header>() {
6666
if let Some($pat) = $headers.get_mut::<$header>() {
6767
$some_match
68-
}
68+
}
6969
} else {
7070
$headers.set($default);
71-
}
72-
}};
71+
}
72+
}};
7373
}
7474

7575
pub use websocket_base::dataframe;

src/result.rs

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -65,48 +65,34 @@ pub enum WebSocketOtherError {
6565
impl fmt::Display for WebSocketOtherError {
6666
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
6767
match self {
68-
WebSocketOtherError::RequestError(e) => write!(fmt, "WebSocket request error: {}", e)?,
68+
WebSocketOtherError::RequestError(e) => write!(fmt, "WebSocket request error: {}", e),
6969
WebSocketOtherError::ResponseError(e) => {
70-
write!(fmt, "WebSocket response error: {}", e)?
70+
write!(fmt, "WebSocket response error: {}", e)
7171
}
7272
WebSocketOtherError::StatusCodeError(e) => write!(
7373
fmt,
7474
"WebSocketError: Received unexpected status code ({})",
7575
e
76-
)?,
77-
WebSocketOtherError::HttpError(e) => write!(fmt, "WebSocket HTTP error: {}", e)?,
78-
WebSocketOtherError::UrlError(e) => write!(fmt, "WebSocket URL parse error: {}", e)?,
79-
WebSocketOtherError::IoError(e) => write!(fmt, "WebSocket I/O error: {}", e)?,
80-
WebSocketOtherError::WebSocketUrlError(e) => e.fmt(fmt)?,
76+
),
77+
WebSocketOtherError::HttpError(e) => write!(fmt, "WebSocket HTTP error: {}", e),
78+
WebSocketOtherError::UrlError(e) => write!(fmt, "WebSocket URL parse error: {}", e),
79+
WebSocketOtherError::IoError(e) => write!(fmt, "WebSocket I/O error: {}", e),
80+
WebSocketOtherError::WebSocketUrlError(e) => e.fmt(fmt),
8181
#[cfg(any(feature = "sync-ssl", feature = "async-ssl"))]
82-
WebSocketOtherError::TlsError(e) => write!(fmt, "WebSocket SSL error: {}", e)?,
83-
_ => write!(fmt, "WebSocketError: {}", self.description())?,
82+
WebSocketOtherError::TlsError(e) => write!(fmt, "WebSocket SSL error: {}", e),
83+
WebSocketOtherError::ProtocolError(e) => write!(fmt, "WebSocketError: {}", e),
84+
WebSocketOtherError::TlsHandshakeFailure => {
85+
write!(fmt, "WebSocketError: {}", "TLS Handshake failure")
86+
}
87+
WebSocketOtherError::TlsHandshakeInterruption => {
88+
write!(fmt, "WebSocketError: {}", "TLS Handshake interrupted")
89+
}
8490
}
85-
Ok(())
8691
}
8792
}
8893

8994
impl Error for WebSocketOtherError {
90-
fn description(&self) -> &str {
91-
match *self {
92-
WebSocketOtherError::RequestError(_) => "WebSocket request error",
93-
WebSocketOtherError::ResponseError(_) => "WebSocket response error",
94-
WebSocketOtherError::HttpError(_) => "HTTP failure",
95-
WebSocketOtherError::UrlError(_) => "URL failure",
96-
#[cfg(any(feature = "sync-ssl", feature = "async-ssl"))]
97-
WebSocketOtherError::TlsError(_) => "TLS failure",
98-
#[cfg(any(feature = "sync-ssl", feature = "async-ssl"))]
99-
WebSocketOtherError::TlsHandshakeFailure => "TLS Handshake failure",
100-
#[cfg(any(feature = "sync-ssl", feature = "async-ssl"))]
101-
WebSocketOtherError::TlsHandshakeInterruption => "TLS Handshake interrupted",
102-
WebSocketOtherError::WebSocketUrlError(_) => "WebSocket URL failure",
103-
WebSocketOtherError::IoError(ref e) => e.description(),
104-
WebSocketOtherError::ProtocolError(e) => e,
105-
WebSocketOtherError::StatusCodeError(_) => "Received unexpected status code",
106-
}
107-
}
108-
109-
fn cause(&self) -> Option<&dyn Error> {
95+
fn source(&self) -> Option<&(dyn Error + 'static)> {
11096
match *self {
11197
WebSocketOtherError::HttpError(ref error) => Some(error),
11298
WebSocketOtherError::UrlError(ref error) => Some(error),
@@ -197,21 +183,16 @@ pub enum WSUrlErrorKind {
197183
impl fmt::Display for WSUrlErrorKind {
198184
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
199185
fmt.write_str("WebSocket Url Error: ")?;
200-
fmt.write_str(self.description())?;
201-
Ok(())
202-
}
203-
}
204-
205-
impl Error for WSUrlErrorKind {
206-
fn description(&self) -> &str {
207-
match *self {
208-
WSUrlErrorKind::CannotSetFragment => "WebSocket URL cannot set fragment",
209-
WSUrlErrorKind::InvalidScheme => "WebSocket URL invalid scheme",
210-
WSUrlErrorKind::NoHostName => "WebSocket URL no host name provided",
186+
match self {
187+
WSUrlErrorKind::CannotSetFragment => fmt.write_str("WebSocket URL cannot set fragment"),
188+
WSUrlErrorKind::InvalidScheme => fmt.write_str("WebSocket URL invalid scheme"),
189+
WSUrlErrorKind::NoHostName => fmt.write_str("WebSocket URL no host name provided"),
211190
}
212191
}
213192
}
214193

194+
impl Error for WSUrlErrorKind {}
195+
215196
impl From<WebSocketOtherError> for WebSocketError {
216197
fn from(e: WebSocketOtherError) -> WebSocketError {
217198
WebSocketError::Other(Box::new(e))

src/server/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ mod tests {
292292
Ok(_) => panic!("expected error"),
293293
Err(e) => match e.error {
294294
HyperIntoWsError::Io(ref e) if e.kind() == io::ErrorKind::WouldBlock => {}
295-
_ => panic!("unexpected error {}"),
295+
e => panic!("unexpected error {}", e),
296296
},
297297
}
298298
}

src/server/upgrade/mod.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -191,28 +191,33 @@ pub enum HyperIntoWsError {
191191

192192
impl Display for HyperIntoWsError {
193193
fn fmt(&self, fmt: &mut Formatter) -> Result<(), fmt::Error> {
194-
fmt.write_str(self.description())
195-
}
196-
}
197-
198-
impl Error for HyperIntoWsError {
199-
fn description(&self) -> &str {
200-
use self::HyperIntoWsError::*;
201194
match *self {
202-
MethodNotGet => "Request method must be GET",
203-
UnsupportedHttpVersion => "Unsupported request HTTP version",
204-
UnsupportedWebsocketVersion => "Unsupported WebSocket version",
205-
NoSecWsKeyHeader => "Missing Sec-WebSocket-Key header",
206-
NoWsUpgradeHeader => "Invalid Upgrade WebSocket header",
207-
NoUpgradeHeader => "Missing Upgrade WebSocket header",
208-
NoWsConnectionHeader => "Invalid Connection WebSocket header",
209-
NoConnectionHeader => "Missing Connection WebSocket header",
210-
Io(ref e) => e.description(),
211-
Parsing(ref e) => e.description(),
195+
HyperIntoWsError::MethodNotGet => fmt.write_str("Request method must be GET"),
196+
HyperIntoWsError::UnsupportedHttpVersion => {
197+
fmt.write_str("Unsupported request HTTP version")
198+
}
199+
HyperIntoWsError::UnsupportedWebsocketVersion => {
200+
fmt.write_str("Unsupported WebSocket version")
201+
}
202+
HyperIntoWsError::NoSecWsKeyHeader => fmt.write_str("Missing Sec-WebSocket-Key header"),
203+
HyperIntoWsError::NoWsUpgradeHeader => {
204+
fmt.write_str("Invalid Upgrade WebSocket header")
205+
}
206+
HyperIntoWsError::NoUpgradeHeader => fmt.write_str("Missing Upgrade WebSocket header"),
207+
HyperIntoWsError::NoWsConnectionHeader => {
208+
fmt.write_str("Invalid Connection WebSocket header")
209+
}
210+
HyperIntoWsError::NoConnectionHeader => {
211+
fmt.write_str("Missing Connection WebSocket header")
212+
}
213+
HyperIntoWsError::Io(ref e) => fmt.write_str(e.to_string().as_str()),
214+
HyperIntoWsError::Parsing(ref e) => fmt.write_str(e.to_string().as_str()),
212215
}
213216
}
217+
}
214218

215-
fn cause(&self) -> Option<&dyn Error> {
219+
impl Error for HyperIntoWsError {
220+
fn source(&self) -> Option<&(dyn Error + 'static)> {
216221
match *self {
217222
HyperIntoWsError::Io(ref e) => Some(e),
218223
HyperIntoWsError::Parsing(ref e) => Some(e),

websocket-base/src/result.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,24 @@ pub enum WebSocketError {
4141

4242
impl fmt::Display for WebSocketError {
4343
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
44+
fmt.write_str("WebSocketError: ")?;
4445
match self {
45-
WebSocketError::Other(x) => x.fmt(fmt)?,
46-
_ => {
47-
fmt.write_str("WebSocketError: ")?;
48-
fmt.write_str(self.description())?;
49-
}
46+
WebSocketError::ProtocolError(_) => fmt.write_str("WebSocket protocol error"),
47+
WebSocketError::DataFrameError(_) => fmt.write_str("WebSocket data frame error"),
48+
WebSocketError::NoDataAvailable => fmt.write_str("No data available"),
49+
WebSocketError::IoError(_) => fmt.write_str("I/O failure"),
50+
WebSocketError::Utf8Error(_) => fmt.write_str("UTF-8 failure"),
51+
WebSocketError::Other(x) => x.fmt(fmt),
5052
}
51-
Ok(())
5253
}
5354
}
5455

5556
impl Error for WebSocketError {
56-
fn description(&self) -> &str {
57-
match *self {
58-
WebSocketError::ProtocolError(_) => "WebSocket protocol error",
59-
WebSocketError::DataFrameError(_) => "WebSocket data frame error",
60-
WebSocketError::NoDataAvailable => "No data available",
61-
WebSocketError::IoError(_) => "I/O failure",
62-
WebSocketError::Utf8Error(_) => "UTF-8 failure",
63-
WebSocketError::Other(ref e) => e.description(),
64-
}
65-
}
66-
67-
#[allow(deprecated)]
68-
fn cause(&self) -> Option<&dyn Error> {
57+
fn source(&self) -> Option<&(dyn Error + 'static)> {
6958
match *self {
7059
WebSocketError::IoError(ref error) => Some(error),
7160
WebSocketError::Utf8Error(ref error) => Some(error),
72-
WebSocketError::Other(ref error) => error.cause(),
61+
WebSocketError::Other(ref error) => error.source(),
7362
_ => None,
7463
}
7564
}

0 commit comments

Comments
 (0)