Skip to content

Commit a15e617

Browse files
Use new other() function
1 parent e2c9e91 commit a15e617

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

pyng/src/tokio/bedrock.rs

+6-22
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,11 @@ impl AsyncPingable for Bedrock {
3838

3939
// Attempt to extract useful information from the payload.
4040
BedrockResponse::extract(&payload).map_or_else(
41-
|| {
42-
Err(Error::IoError(io::Error::new(
43-
io::ErrorKind::Other,
44-
"Invalid Payload",
45-
)))
46-
},
41+
|| Err(Error::IoError(io::Error::other("Invalid Payload"))),
4742
|response| Ok((latency, response)),
4843
)
4944
} else {
50-
Err(Error::IoError(io::Error::new(
51-
io::ErrorKind::Other,
52-
"Invalid Packet Response",
53-
)))
45+
Err(Error::IoError(io::Error::other("Invalid Packet Response")))
5446
}
5547
}
5648
}
@@ -64,8 +56,7 @@ trait AsyncReadBedrockExt: AsyncRead + AsyncReadExt + Unpin {
6456
let len = self.read_u16().await?;
6557
let mut buf = vec![0; len as usize];
6658
self.read_exact(&mut buf).await?;
67-
String::from_utf8(buf)
68-
.map_err(|_| io::Error::new(io::ErrorKind::Other, "Invalid UTF-8 String."))
59+
String::from_utf8(buf).map_err(|_| io::Error::other("Invalid UTF-8 String."))
6960
}
7061
}
7162

@@ -126,10 +117,7 @@ impl Connection {
126117
self.socket.send(&buf).await?;
127118
}
128119
Packet::UnconnectedPong { .. } => {
129-
return Err(io::Error::new(
130-
io::ErrorKind::Other,
131-
"Invalid C -> S Packet",
132-
));
120+
return Err(io::Error::other("Invalid C -> S Packet"));
133121
}
134122
}
135123

@@ -152,8 +140,7 @@ impl Connection {
152140
buf.read_exact(&mut tmp).await?;
153141

154142
if tmp != OFFLINE_MESSAGE_DATA_ID {
155-
return Err(io::Error::new(
156-
io::ErrorKind::Other,
143+
return Err(io::Error::other(
157144
"incorrect offline message data ID received",
158145
));
159146
}
@@ -166,10 +153,7 @@ impl Connection {
166153
payload,
167154
})
168155
}
169-
_ => Err(io::Error::new(
170-
io::ErrorKind::Other,
171-
"Invalid S -> C Packet",
172-
)),
156+
_ => Err(io::Error::other("Invalid S -> C Packet")),
173157
}
174158
}
175159
}

pyng/src/tokio/java.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ trait AsyncReadJavaExt: AsyncRead + AsyncReadExt + Unpin {
6969
return Ok(res);
7070
}
7171
}
72-
Err(io::Error::new(io::ErrorKind::Other, "VarInt too big!"))
72+
Err(io::Error::other("VarInt too big!"))
7373
}
7474

7575
async fn read_string(&mut self) -> io::Result<String> {
@@ -105,7 +105,7 @@ trait AsyncWriteJavaExt: AsyncWrite + AsyncWriteExt + Unpin {
105105
self.write_u8((val & 0x7F | 0x80) as u8).await?;
106106
val >>= 7;
107107
}
108-
Err(io::Error::new(io::ErrorKind::Other, "VarInt too big!"))
108+
Err(io::Error::other("VarInt too big!"))
109109
}
110110

111111
async fn write_string(&mut self, s: &str) -> io::Result<()> {

0 commit comments

Comments
 (0)