Skip to content

Commit 1847570

Browse files
weihanglopetrochenkov
authored andcommitted
refactor: find_jobserver_auth returns a slice
1 parent dfa034f commit 1847570

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,10 @@ impl Client {
279279
}
280280
};
281281

282-
let (arg, pos) = match find_jobserver_auth(var) {
283-
Some((arg, pos)) => (arg, pos),
282+
let s = match find_jobserver_auth(var) {
283+
Some(s) => s,
284284
None => return FromEnv::new_err(FromEnvErrorInner::NoJobserver, env, var_os),
285285
};
286-
287-
let s = var[pos + arg.len()..].split(' ').next().unwrap();
288286
match imp::Client::open(s, check_pipe) {
289287
Ok(c) => FromEnv::new_ok(Client { inner: Arc::new(c) }, env, var_os),
290288
Err(err) => FromEnv::new_err(err, env, var_os),
@@ -584,11 +582,11 @@ impl HelperState {
584582
}
585583
}
586584

587-
fn find_jobserver_auth(var: &str) -> Option<(&str, usize)> {
585+
fn find_jobserver_auth(var: &str) -> Option<&str> {
588586
["--jobserver-fds=", "--jobserver-auth="]
589587
.iter()
590-
.map(|&arg| var.find(arg).map(|pos| (arg, pos)))
591-
.find_map(|pos| pos)
588+
.find_map(|&arg| var.split_once(arg).map(|(_, s)| s))
589+
.and_then(|s| s.split(' ').next())
592590
}
593591

594592
#[test]

0 commit comments

Comments
 (0)