Skip to content

Commit bb3b8a1

Browse files
author
yngrtc
committed
fix clippy warn
1 parent 1f94514 commit bb3b8a1

File tree

14 files changed

+45
-59
lines changed

14 files changed

+45
-59
lines changed

data/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl From<Error> for io::Error {
4848
e @ Error::ErrStreamClosed => {
4949
io::Error::new(io::ErrorKind::ConnectionAborted, e.to_string())
5050
}
51-
e => io::Error::new(io::ErrorKind::Other, e.to_string()),
51+
e => io::Error::other(e.to_string()),
5252
}
5353
}
5454
}

dtls/src/cipher_suite/cipher_suite_chacha20_poly1305_sha256.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ impl CipherSuiteChaCha20Poly1305Sha256 {
1414
const PRF_IV_LEN: usize = 12;
1515

1616
pub fn new(rsa: bool) -> Self {
17-
CipherSuiteChaCha20Poly1305Sha256 {
18-
rsa: rsa,
19-
cipher: None,
20-
}
17+
CipherSuiteChaCha20Poly1305Sha256 { rsa, cipher: None }
2118
}
2219
}
2320

ice/src/agent/agent_transport.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,17 @@ impl AgentConn {
166166
#[async_trait]
167167
impl Conn for AgentConn {
168168
async fn connect(&self, _addr: SocketAddr) -> std::result::Result<(), util::Error> {
169-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
169+
Err(io::Error::other("Not applicable").into())
170170
}
171171

172172
async fn recv(&self, buf: &mut [u8]) -> std::result::Result<usize, util::Error> {
173173
if self.done.load(Ordering::SeqCst) {
174-
return Err(io::Error::new(io::ErrorKind::Other, "Conn is closed").into());
174+
return Err(io::Error::other("Conn is closed").into());
175175
}
176176

177177
let n = match self.buffer.read(buf, None).await {
178178
Ok(n) => n,
179-
Err(err) => return Err(io::Error::new(io::ErrorKind::Other, err.to_string()).into()),
179+
Err(err) => return Err(io::Error::other(err.to_string()).into()),
180180
};
181181
self.bytes_received.fetch_add(n, Ordering::SeqCst);
182182

@@ -191,13 +191,13 @@ impl Conn for AgentConn {
191191
let n = self.recv(buf).await?;
192192
Ok((n, raddr))
193193
} else {
194-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
194+
Err(io::Error::other("Not applicable").into())
195195
}
196196
}
197197

198198
async fn send(&self, buf: &[u8]) -> std::result::Result<usize, util::Error> {
199199
if self.done.load(Ordering::SeqCst) {
200-
return Err(io::Error::new(io::ErrorKind::Other, "Conn is closed").into());
200+
return Err(io::Error::other("Conn is closed").into());
201201
}
202202

203203
if is_message(buf) {
@@ -217,7 +217,7 @@ impl Conn for AgentConn {
217217
self.bytes_sent.fetch_add(buf.len(), Ordering::SeqCst);
218218
Ok(n)
219219
}
220-
Err(err) => Err(io::Error::new(io::ErrorKind::Other, err.to_string()).into()),
220+
Err(err) => Err(io::Error::other(err.to_string()).into()),
221221
}
222222
}
223223

@@ -226,7 +226,7 @@ impl Conn for AgentConn {
226226
_buf: &[u8],
227227
_target: SocketAddr,
228228
) -> std::result::Result<usize, util::Error> {
229-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
229+
Err(io::Error::other("Not applicable").into())
230230
}
231231

232232
fn local_addr(&self) -> std::result::Result<SocketAddr, util::Error> {

ice/src/udp_mux/udp_mux_conn.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,19 @@ impl UDPMuxConnInner {
267267
#[async_trait]
268268
impl Conn for UDPMuxConn {
269269
async fn connect(&self, _addr: SocketAddr) -> ConnResult<()> {
270-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
270+
Err(io::Error::other("Not applicable").into())
271271
}
272272

273273
async fn recv(&self, _buf: &mut [u8]) -> ConnResult<usize> {
274-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
274+
Err(io::Error::other("Not applicable").into())
275275
}
276276

277277
async fn recv_from(&self, buf: &mut [u8]) -> ConnResult<(usize, SocketAddr)> {
278278
self.inner.recv_from(buf).await
279279
}
280280

281281
async fn send(&self, _buf: &[u8]) -> ConnResult<usize> {
282-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
282+
Err(io::Error::other("Not applicable").into())
283283
}
284284

285285
async fn send_to(&self, buf: &[u8], target: SocketAddr) -> ConnResult<usize> {

sctp/src/association/association_internal.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,11 +1040,7 @@ impl AssociationInternal {
10401040
bytes_queued += s.get_num_bytes_in_reassembly_queue().await as u32;
10411041
}
10421042

1043-
if bytes_queued >= self.max_receive_buffer_size {
1044-
0
1045-
} else {
1046-
self.max_receive_buffer_size - bytes_queued
1047-
}
1043+
self.max_receive_buffer_size.saturating_sub(bytes_queued)
10481044
}
10491045

10501046
pub(crate) fn open_stream(

sctp/src/association/association_internal/association_internal_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ struct DumbConn;
1616
#[async_trait]
1717
impl Conn for DumbConn {
1818
async fn connect(&self, _addr: SocketAddr) -> Result<()> {
19-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
19+
Err(io::Error::other("Not applicable").into())
2020
}
2121

2222
async fn recv(&self, _b: &mut [u8]) -> Result<usize> {
2323
Ok(0)
2424
}
2525

2626
async fn recv_from(&self, _buf: &mut [u8]) -> Result<(usize, SocketAddr)> {
27-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
27+
Err(io::Error::other("Not applicable").into())
2828
}
2929

3030
async fn send(&self, _b: &[u8]) -> Result<usize> {
3131
Ok(0)
3232
}
3333

3434
async fn send_to(&self, _buf: &[u8], _target: SocketAddr) -> Result<usize> {
35-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
35+
Err(io::Error::other("Not applicable").into())
3636
}
3737

3838
fn local_addr(&self) -> Result<SocketAddr> {

sctp/src/association/association_test.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,7 @@ type UResult<T> = std::result::Result<T, util::Error>;
20972097
#[async_trait]
20982098
impl Conn for FakeEchoConn {
20992099
async fn connect(&self, _addr: SocketAddr) -> UResult<()> {
2100-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
2100+
Err(io::Error::other("Not applicable").into())
21012101
}
21022102

21032103
async fn recv(&self, b: &mut [u8]) -> UResult<usize> {
@@ -2115,25 +2115,25 @@ impl Conn for FakeEchoConn {
21152115
}
21162116

21172117
async fn recv_from(&self, _buf: &mut [u8]) -> UResult<(usize, SocketAddr)> {
2118-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
2118+
Err(io::Error::other("Not applicable").into())
21192119
}
21202120

21212121
async fn send(&self, b: &[u8]) -> UResult<usize> {
21222122
let wr_tx = self.wr_tx.lock().await;
21232123
match wr_tx.send(b.to_vec()).await {
21242124
Ok(_) => {}
2125-
Err(err) => return Err(io::Error::new(io::ErrorKind::Other, err.to_string()).into()),
2125+
Err(err) => return Err(io::Error::other(err.to_string()).into()),
21262126
};
21272127
self.bytes_sent.fetch_add(b.len(), Ordering::SeqCst);
21282128
Ok(b.len())
21292129
}
21302130

21312131
async fn send_to(&self, _buf: &[u8], _target: SocketAddr) -> UResult<usize> {
2132-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
2132+
Err(io::Error::other("Not applicable").into())
21332133
}
21342134

21352135
fn local_addr(&self) -> UResult<SocketAddr> {
2136-
Err(io::Error::new(io::ErrorKind::AddrNotAvailable, "Addr Not Available").into())
2136+
Err(io::Error::other("Not applicable").into())
21372137
}
21382138

21392139
fn remote_addr(&self) -> Option<SocketAddr> {

sctp/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl From<Error> for io::Error {
232232
e @ Error::ErrStreamClosed => {
233233
io::Error::new(io::ErrorKind::ConnectionAborted, e.to_string())
234234
}
235-
e => io::Error::new(io::ErrorKind::Other, e.to_string()),
235+
e => io::Error::other(e.to_string()),
236236
}
237237
}
238238
}

turn/src/client/relay_conn.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ impl<T: 'static + RelayConnObserver + Send + Sync> RelayConn<T> {
106106
#[async_trait]
107107
impl<T: RelayConnObserver + Send + Sync> Conn for RelayConn<T> {
108108
async fn connect(&self, _addr: SocketAddr) -> Result<(), util::Error> {
109-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
109+
Err(io::Error::other("Not applicable").into())
110110
}
111111

112112
async fn recv(&self, _buf: &mut [u8]) -> Result<usize, util::Error> {
113-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
113+
Err(io::Error::other("Not applicable").into())
114114
}
115115

116116
/// Reads a packet from the connection,
@@ -147,7 +147,7 @@ impl<T: RelayConnObserver + Send + Sync> Conn for RelayConn<T> {
147147
}
148148

149149
async fn send(&self, _buf: &[u8]) -> Result<usize, util::Error> {
150-
Err(io::Error::new(io::ErrorKind::Other, "Not applicable").into())
150+
Err(io::Error::other("Not applicable").into())
151151
}
152152

153153
/// Writes a packet with payload `p` to `addr`.
@@ -159,7 +159,7 @@ impl<T: RelayConnObserver + Send + Sync> Conn for RelayConn<T> {
159159
let mut relay_conn = self.relay_conn.lock().await;
160160
match relay_conn.send_to(p, addr).await {
161161
Ok(n) => Ok(n),
162-
Err(err) => Err(io::Error::new(io::ErrorKind::Other, err.to_string()).into()),
162+
Err(err) => Err(io::Error::other(err.to_string()).into()),
163163
}
164164
}
165165

util/src/conn/conn_bridge.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct BridgeConn {
2424
#[async_trait]
2525
impl Conn for BridgeConn {
2626
async fn connect(&self, _addr: SocketAddr) -> Result<()> {
27-
Err(Error::new(ErrorKind::Other, "Not applicable").into())
27+
Err(Error::other("Not applicable").into())
2828
}
2929

3030
async fn recv(&self, b: &mut [u8]) -> Result<usize> {
@@ -52,7 +52,7 @@ impl Conn for BridgeConn {
5252
}
5353

5454
async fn send_to(&self, _buf: &[u8], _target: SocketAddr) -> Result<usize> {
55-
Err(Error::new(ErrorKind::Other, "Not applicable").into())
55+
Err(Error::other("Not applicable").into())
5656
}
5757

5858
fn local_addr(&self) -> Result<SocketAddr> {

0 commit comments

Comments
 (0)