aboutsummaryrefslogtreecommitdiff
path: root/mingling/src/parser/picker
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2026-05-31 02:42:52 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-31 17:19:20 +0800
commit2aa7bda3cb21ce6c052b82e08bcab79a625d04f2 (patch)
treef10b89007fc67ca1a948f34abe6869b49296b932 /mingling/src/parser/picker
parent3aa409a55e4f2f0ab41b0949cc06eb13c2da4a43 (diff)
Enhance code quality across the entire codebase
Diffstat (limited to 'mingling/src/parser/picker')
-rw-r--r--mingling/src/parser/picker/bools.rs4
-rw-r--r--mingling/src/parser/picker/builtin.rs4
-rw-r--r--mingling/src/parser/picker/path.rs2
-rw-r--r--mingling/src/parser/picker/path/rule.rs12
4 files changed, 19 insertions, 3 deletions
diff --git a/mingling/src/parser/picker/bools.rs b/mingling/src/parser/picker/bools.rs
index aa2335a..ede8812 100644
--- a/mingling/src/parser/picker/bools.rs
+++ b/mingling/src/parser/picker/bools.rs
@@ -37,10 +37,12 @@ impl std::ops::Deref for Yes {
}
impl Yes {
+ #[must_use]
pub fn is_yes(&self) -> bool {
matches!(self, Yes::Yes)
}
+ #[must_use]
pub fn is_no(&self) -> bool {
matches!(self, Yes::No)
}
@@ -92,10 +94,12 @@ impl std::ops::Deref for True {
}
impl True {
+ #[must_use]
pub fn is_true(&self) -> bool {
matches!(self, True::True)
}
+ #[must_use]
pub fn is_false(&self) -> bool {
matches!(self, True::False)
}
diff --git a/mingling/src/parser/picker/builtin.rs b/mingling/src/parser/picker/builtin.rs
index e7a178d..6194955 100644
--- a/mingling/src/parser/picker/builtin.rs
+++ b/mingling/src/parser/picker/builtin.rs
@@ -68,7 +68,7 @@ impl Pickable for usize {
let picked = args.pick_argument(flag)?;
let size_parse = Size::from_str(picked.as_str());
match size_parse {
- Ok(size) => Some(size.bytes() as usize),
+ Ok(size) => usize::try_from(size.bytes()).ok(),
Err(_) => None,
}
}
@@ -84,7 +84,7 @@ impl Pickable for Vec<usize> {
for picked in picked_vec {
let size_parse = Size::from_str(picked.as_str());
match size_parse {
- Ok(size) => result.push(size.bytes() as usize),
+ Ok(size) => result.push(usize::try_from(size.bytes()).unwrap_or(usize::MAX)),
Err(_) => return None,
}
}
diff --git a/mingling/src/parser/picker/path.rs b/mingling/src/parser/picker/path.rs
index c97250f..961542e 100644
--- a/mingling/src/parser/picker/path.rs
+++ b/mingling/src/parser/picker/path.rs
@@ -91,7 +91,7 @@ impl<T: Into<PathBuf>> PathChecker for T where T: Into<PathBuf> {}
fn check_paths(path: impl Into<Vec<PathBuf>>, rule: &PathCheckRule) -> Result<(), ()> {
let paths = path.into();
- for p in paths.iter() {
+ for p in &paths {
check_exist(p, rule)?;
check_type(p, rule)?;
}
diff --git a/mingling/src/parser/picker/path/rule.rs b/mingling/src/parser/picker/path/rule.rs
index 07df705..bf5cab3 100644
--- a/mingling/src/parser/picker/path/rule.rs
+++ b/mingling/src/parser/picker/path/rule.rs
@@ -25,6 +25,7 @@ pub struct PathTypeCheck {
impl PathCheckRule {
/// Creates a new `PathCheckRule` with default values
+ #[must_use]
pub fn new() -> Self {
Self {
exist_check: None,
@@ -33,6 +34,7 @@ impl PathCheckRule {
}
/// Allows the path to be a file
+ #[must_use]
pub fn allow_file(self) -> Self {
match self.type_check {
Some(type_check) => Self {
@@ -55,6 +57,7 @@ impl PathCheckRule {
}
/// Allows the path to be a directory
+ #[must_use]
pub fn allow_dir(self) -> Self {
match self.type_check {
Some(type_check) => Self {
@@ -77,6 +80,7 @@ impl PathCheckRule {
}
/// Allows the path to be a symlink
+ #[must_use]
pub fn allow_symlink(self) -> Self {
match self.type_check {
Some(type_check) => Self {
@@ -99,6 +103,7 @@ impl PathCheckRule {
}
/// Denies the path from being a file
+ #[must_use]
pub fn deny_file(self) -> Self {
match self.type_check {
Some(type_check) => Self {
@@ -121,6 +126,7 @@ impl PathCheckRule {
}
/// Denies the path from being a directory
+ #[must_use]
pub fn deny_dir(self) -> Self {
match self.type_check {
Some(type_check) => Self {
@@ -143,6 +149,7 @@ impl PathCheckRule {
}
/// Denies the path from being a symlink
+ #[must_use]
pub fn deny_symlink(self) -> Self {
match self.type_check {
Some(type_check) => Self {
@@ -165,6 +172,7 @@ impl PathCheckRule {
}
/// Requires the path to be a file (overrides type checks)
+ #[must_use]
pub fn must_file(self) -> Self {
Self {
type_check: Some(PathTypeCheck {
@@ -177,6 +185,7 @@ impl PathCheckRule {
}
/// Requires the path to be a directory (overrides type checks)
+ #[must_use]
pub fn must_dir(self) -> Self {
Self {
type_check: Some(PathTypeCheck {
@@ -189,6 +198,7 @@ impl PathCheckRule {
}
/// Requires the path to be a symlink (overrides type checks)
+ #[must_use]
pub fn must_symlink(self) -> Self {
Self {
type_check: Some(PathTypeCheck {
@@ -201,6 +211,7 @@ impl PathCheckRule {
}
/// Requires the path to exist
+ #[must_use]
pub fn must_exist(self) -> Self {
Self {
exist_check: Some(PathExistCheck::Exists),
@@ -209,6 +220,7 @@ impl PathCheckRule {
}
/// Requires the path to not exist
+ #[must_use]
pub fn must_not_exist(self) -> Self {
Self {
exist_check: Some(PathExistCheck::NotExists),