-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: allow user to set rayon threads
BREAKING CHANGE: a new field named `threads` is added to `Args` and `Sub`
- Loading branch information
Showing
10 changed files
with
74 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use derive_more::{Display, Error}; | ||
use std::{num::ParseIntError, str::FromStr}; | ||
|
||
const AUTO: &str = "auto"; | ||
const MAX: &str = "max"; | ||
|
||
/// Number of rayon threads. | ||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Display)] | ||
pub enum Threads { | ||
#[default] | ||
#[display("{AUTO}")] | ||
Auto, | ||
#[display("{MAX}")] | ||
Max, | ||
Fixed(usize), | ||
} | ||
|
||
/// Error that occurs when converting a string to an instance of [`Threads`]. | ||
#[derive(Debug, Display, Clone, PartialEq, Eq, Error)] | ||
pub enum FromStrError { | ||
#[display("Value is neither {AUTO:?}, {MAX:?}, nor a number: {_0}")] | ||
InvalidSyntax(ParseIntError), | ||
} | ||
|
||
impl FromStr for Threads { | ||
type Err = FromStrError; | ||
fn from_str(value: &str) -> Result<Self, Self::Err> { | ||
let value = value.trim(); | ||
match value { | ||
AUTO => return Ok(Threads::Auto), | ||
MAX => return Ok(Threads::Max), | ||
_ => {} | ||
}; | ||
value | ||
.parse() | ||
.map_err(FromStrError::InvalidSyntax) | ||
.map(Threads::Fixed) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters