From dfa034fed13a920a11ea2175a70d35262e043356 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 31 Jan 2024 16:35:18 -0500 Subject: [PATCH] refactor: extract `--jobserver-auth=` to a free function --- src/lib.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3091aea..7ac618e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -279,11 +279,7 @@ impl Client { } }; - let (arg, pos) = match ["--jobserver-fds=", "--jobserver-auth="] - .iter() - .map(|&arg| var.find(arg).map(|pos| (arg, pos))) - .find_map(|pos| pos) - { + let (arg, pos) = match find_jobserver_auth(var) { Some((arg, pos)) => (arg, pos), None => return FromEnv::new_err(FromEnvErrorInner::NoJobserver, env, var_os), }; @@ -588,6 +584,13 @@ impl HelperState { } } +fn find_jobserver_auth(var: &str) -> Option<(&str, usize)> { + ["--jobserver-fds=", "--jobserver-auth="] + .iter() + .map(|&arg| var.find(arg).map(|pos| (arg, pos))) + .find_map(|pos| pos) +} + #[test] fn no_helper_deadlock() { let x = crate::Client::new(32).unwrap();