Skip to content

Commit 5d7be37

Browse files
committed
Merge #180: feat!: Change ConfigBuilder::timeout to accept Option<Duration>
5dc4bb6 ci: bump clippy to 1.90.0 (valued mammal) e31cf47 feat!: Change ConfigBuilder::timeout to accept Option<Duration> (valued mammal) Pull request description: Change `ConfigBuilder::timeout` to accept `Option<Duration>`. This makes the API more explicit and less error prone, as the caller no longer needs to assume the units of the given duration. Also updated the code to run clippy check in CI using rust 1.90.0. BREAKING: The `timeout` method on `ConfigBuilder` is changed to accept a `timeout: Option<Duration>`. Previously it was `Option<u8>`. fix #151 fix #175 Supersedes #179 ACKs for top commit: oleonardolima: ACK 5dc4bb6 Tree-SHA512: cd6ca6fdd91dcf6f193327ca40f6d37ea8b1b548102f080d0b72a0df509f6455aa50ee43148e4746ca6b295a30a78cb7d786fb0e90c050448e96e122a5b8c92d
2 parents 761796c + 5dc4bb6 commit 5d7be37

File tree

6 files changed

+22
-54
lines changed

6 files changed

+22
-54
lines changed

.github/workflows/cont_integration.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,10 @@ jobs:
6262
runs-on: ubuntu-latest
6363
steps:
6464
- uses: actions/checkout@v4
65-
- uses: dtolnay/rust-toolchain@stable
65+
- uses: dtolnay/rust-toolchain@v1
6666
with:
67-
toolchain: 1.84.0
67+
toolchain: 1.90.0
6868
components: clippy
6969
- name: Rust Cache
7070
uses: Swatinem/[email protected]
71-
- uses: actions-rs/clippy-check@v1
72-
with:
73-
token: ${{ secrets.GITHUB_TOKEN }}
74-
args: --all-features --all-targets -- -D warnings
71+
- run: cargo clippy --all-features --all-targets -- -D warnings

src/batch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl Batch {
8888
}
8989

9090
/// Returns an iterator on the batch
91-
pub fn iter(&self) -> BatchIter {
91+
pub fn iter(&self) -> BatchIter<'_> {
9292
BatchIter {
9393
batch: self,
9494
index: 0,

src/client.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,9 @@ mod tests {
448448
let now = Instant::now();
449449
let client = Client::from_config(
450450
&endpoint,
451-
crate::config::ConfigBuilder::new().timeout(Some(5)).build(),
451+
crate::config::ConfigBuilder::new()
452+
.timeout(Some(Duration::from_secs(5)))
453+
.build(),
452454
);
453455
let elapsed = now.elapsed();
454456

src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ impl ConfigBuilder {
5555
}
5656

5757
/// Sets the timeout
58-
pub fn timeout(mut self, timeout: Option<u8>) -> Self {
59-
self.config.timeout = timeout.map(|t| Duration::from_secs(t as u64));
58+
pub fn timeout(mut self, timeout: Option<Duration>) -> Self {
59+
self.config.timeout = timeout;
6060
self
6161
}
6262

src/socks/v4.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ fn read_response(socket: &mut TcpStream) -> io::Result<SocketAddrV4> {
1818

1919
match response.read_u8()? {
2020
90 => {}
21-
91 => {
22-
return Err(io::Error::new(
23-
io::ErrorKind::Other,
24-
"request rejected or failed",
25-
))
26-
}
21+
91 => return Err(io::Error::other("request rejected or failed")),
2722
92 => {
2823
return Err(io::Error::new(
2924
io::ErrorKind::PermissionDenied,

src/socks/v5.rs

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ fn read_addr<R: Read>(socket: &mut R) -> io::Result<TargetAddr> {
3737
ip, port, 0, 0,
3838
))))
3939
}
40-
_ => Err(io::Error::new(
41-
io::ErrorKind::Other,
42-
"unsupported address type",
43-
)),
40+
_ => Err(io::Error::other("unsupported address type")),
4441
}
4542
}
4643

@@ -54,35 +51,15 @@ fn read_response(socket: &mut TcpStream) -> io::Result<TargetAddr> {
5451

5552
match socket.read_u8()? {
5653
0 => {}
57-
1 => {
58-
return Err(io::Error::new(
59-
io::ErrorKind::Other,
60-
"general SOCKS server failure",
61-
))
62-
}
63-
2 => {
64-
return Err(io::Error::new(
65-
io::ErrorKind::Other,
66-
"connection not allowed by ruleset",
67-
))
68-
}
69-
3 => return Err(io::Error::new(io::ErrorKind::Other, "network unreachable")),
70-
4 => return Err(io::Error::new(io::ErrorKind::Other, "host unreachable")),
71-
5 => return Err(io::Error::new(io::ErrorKind::Other, "connection refused")),
72-
6 => return Err(io::Error::new(io::ErrorKind::Other, "TTL expired")),
73-
7 => {
74-
return Err(io::Error::new(
75-
io::ErrorKind::Other,
76-
"command not supported",
77-
))
78-
}
79-
8 => {
80-
return Err(io::Error::new(
81-
io::ErrorKind::Other,
82-
"address kind not supported",
83-
))
84-
}
85-
_ => return Err(io::Error::new(io::ErrorKind::Other, "unknown error")),
54+
1 => return Err(io::Error::other("general SOCKS server failure")),
55+
2 => return Err(io::Error::other("connection not allowed by ruleset")),
56+
3 => return Err(io::Error::other("network unreachable")),
57+
4 => return Err(io::Error::other("host unreachable")),
58+
5 => return Err(io::Error::other("connection refused")),
59+
6 => return Err(io::Error::other("TTL expired")),
60+
7 => return Err(io::Error::other("command not supported")),
61+
8 => return Err(io::Error::other("address kind not supported")),
62+
_ => return Err(io::Error::other("unknown error")),
8663
}
8764

8865
if socket.read_u8()? != 0 {
@@ -227,14 +204,11 @@ impl Socks5Stream {
227204
}
228205

229206
if selected_method == 0xff {
230-
return Err(io::Error::new(
231-
io::ErrorKind::Other,
232-
"no acceptable auth methods",
233-
));
207+
return Err(io::Error::other("no acceptable auth methods"));
234208
}
235209

236210
if selected_method != auth.id() && selected_method != Authentication::None.id() {
237-
return Err(io::Error::new(io::ErrorKind::Other, "unknown auth method"));
211+
return Err(io::Error::other("unknown auth method"));
238212
}
239213

240214
match *auth {

0 commit comments

Comments
 (0)