Skip to content

Commit 65bf01a

Browse files
committed
[temp] use new name 'from_env_ext' for new behavior
1 parent ff334c2 commit 65bf01a

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
//!
3030
//! // See API documentation for why this is `unsafe`
3131
//! let client = match unsafe { Client::from_env() } {
32-
//! Ok(client) => client,
33-
//! Err(_) => panic!("client not configured"),
32+
//! Some(client) => client,
33+
//! None => panic!("client not configured"),
3434
//! };
3535
//! ```
3636
//!
@@ -269,7 +269,7 @@ impl Client {
269269
///
270270
/// Note, though, that on Windows it should be safe to call this function
271271
/// any number of times.
272-
pub unsafe fn from_env() -> Result<Client, ErrFromEnv> {
272+
pub unsafe fn from_env_ext() -> Result<Client, ErrFromEnv> {
273273
let (env, var) = ["CARGO_MAKEFLAGS", "MAKEFLAGS", "MFLAGS"]
274274
.iter()
275275
.map(|&env| env::var(env).map(|var| (env, var)))
@@ -289,6 +289,14 @@ impl Client {
289289
}
290290
}
291291

292+
/// Attempts to connect to the jobserver specified in this process's
293+
/// environment.
294+
///
295+
/// Wraps `from_env_ext` and discards error details.
296+
pub unsafe fn from_env() -> Option<Client> {
297+
Self::from_env_ext().ok()
298+
}
299+
292300
/// Acquires a token from this jobserver client.
293301
///
294302
/// This function will block the calling thread until a new token can be

tests/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ const TESTS: &[Test] = &[
3535
make_args: &[],
3636
rule: &|me| me.to_string(),
3737
f: &|| {
38-
assert!(unsafe { Client::from_env().is_err() });
38+
assert!(unsafe { Client::from_env().is_none() });
3939
},
4040
},
4141
Test {
4242
name: "no j args with plus",
4343
make_args: &[],
4444
rule: &|me| format!("+{}", me),
4545
f: &|| {
46-
assert!(unsafe { Client::from_env().is_err() });
46+
assert!(unsafe { Client::from_env().is_none() });
4747
},
4848
},
4949
Test {
5050
name: "j args with plus",
5151
make_args: &["-j2"],
5252
rule: &|me| format!("+{}", me),
5353
f: &|| {
54-
assert!(unsafe { Client::from_env().is_ok() });
54+
assert!(unsafe { Client::from_env().is_some() });
5555
},
5656
},
5757
Test {

0 commit comments

Comments
 (0)