-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Must be greater than zero - Must be a power of two (but can override with `--allow uneven-piece-length` - Must be greater than 16KiB (but can override with `--allow small-piece-length` - Must be less than u32 max type: changed
- Loading branch information
Showing
7 changed files
with
246 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use crate::common::*; | ||
|
||
#[derive(Eq, PartialEq, Debug, Copy, Clone, Ord, PartialOrd)] | ||
pub(crate) enum Lint { | ||
UnevenPieceLength, | ||
SmallPieceLength, | ||
} | ||
|
||
const UNEVEN_PIECE_LENGTH: &str = "uneven-piece-length"; | ||
const SMALL_PIECE_LENGTH: &str = "small-piece-length"; | ||
|
||
impl Lint { | ||
pub(crate) fn name(self) -> &'static str { | ||
match self { | ||
Self::UnevenPieceLength => UNEVEN_PIECE_LENGTH, | ||
Self::SmallPieceLength => SMALL_PIECE_LENGTH, | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for Lint { | ||
type Err = Error; | ||
|
||
fn from_str(text: &str) -> Result<Self, Self::Err> { | ||
match text.replace('_', "-").to_lowercase().as_str() { | ||
UNEVEN_PIECE_LENGTH => Ok(Self::UnevenPieceLength), | ||
SMALL_PIECE_LENGTH => Ok(Self::SmallPieceLength), | ||
_ => Err(Error::LintUnknown { | ||
text: text.to_string(), | ||
}), | ||
} | ||
} | ||
} | ||
|
||
impl Display for Lint { | ||
fn fmt(&self, f: &mut Formatter) -> fmt::Result { | ||
write!(f, "{}", self.name()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn from_str_ok() { | ||
assert_eq!( | ||
Lint::UnevenPieceLength, | ||
"uneven_piece_length".parse().unwrap() | ||
); | ||
|
||
assert_eq!( | ||
Lint::UnevenPieceLength, | ||
"uneven-piece-length".parse().unwrap() | ||
); | ||
|
||
assert_eq!( | ||
Lint::UnevenPieceLength, | ||
"UNEVEN-piece-length".parse().unwrap() | ||
); | ||
} | ||
|
||
#[test] | ||
fn from_str_err() { | ||
assert_matches!( | ||
"foo".parse::<Lint>(), | ||
Err(Error::LintUnknown { text }) if text == "foo" | ||
); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -52,6 +52,7 @@ mod hasher; | |
mod info; | ||
mod into_u64; | ||
mod into_usize; | ||
mod lint; | ||
mod metainfo; | ||
mod mode; | ||
mod opt; | ||
|
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