mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-21 11:20:03 +00:00
Refactor: Extract new mod jobserver_client.rs
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
2490cd5a84
commit
a1d7a7c117
2 changed files with 23 additions and 18 deletions
20
src/helpers/jobserver_client.rs
Normal file
20
src/helpers/jobserver_client.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use std::num::NonZeroUsize;
|
||||
use std::thread::available_parallelism;
|
||||
|
||||
use crate::BinstallError;
|
||||
|
||||
pub fn create_jobserver_client() -> Result<jobserver::Client, BinstallError> {
|
||||
use jobserver::Client;
|
||||
|
||||
// Safety:
|
||||
//
|
||||
// Client::from_env is unsafe because from_raw_fd is unsafe.
|
||||
// It doesn't do anything that is actually unsafe, like
|
||||
// dereferencing pointer.
|
||||
if let Some(client) = unsafe { Client::from_env() } {
|
||||
Ok(client)
|
||||
} else {
|
||||
let ncore = available_parallelism().map(NonZeroUsize::get).unwrap_or(1);
|
||||
Ok(Client::new(ncore)?)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue