aboutsummaryrefslogtreecommitdiff
path: root/arg_picker/src/value
diff options
context:
space:
mode:
Diffstat (limited to 'arg_picker/src/value')
-rw-r--r--arg_picker/src/value/flag.rs18
-rw-r--r--arg_picker/src/value/paths.rs21
-rw-r--r--arg_picker/src/value/vec_until.rs9
3 files changed, 30 insertions, 18 deletions
diff --git a/arg_picker/src/value/flag.rs b/arg_picker/src/value/flag.rs
index c0673bd..6449d65 100644
--- a/arg_picker/src/value/flag.rs
+++ b/arg_picker/src/value/flag.rs
@@ -80,9 +80,9 @@ impl Flag {
/// [`Active`]: Flag::Active
/// [`Inactive`]: Flag::Inactive
#[must_use]
- #[inline(always)]
+ #[inline]
pub fn bool(&self) -> bool {
- *self == Flag::Active
+ *self == Self::Active
}
}
@@ -101,7 +101,7 @@ impl PartialEq<Flag> for bool {
impl From<bool> for Flag {
fn from(value: bool) -> Self {
- if value { Flag::Active } else { Flag::Inactive }
+ if value { Self::Active } else { Self::Inactive }
}
}
@@ -127,19 +127,19 @@ impl Deref for Flag {
fn deref(&self) -> &bool {
match self {
- Flag::Active => &true,
- Flag::Inactive => &false,
+ Self::Active => &true,
+ Self::Inactive => &false,
}
}
}
impl Not for Flag {
- type Output = Flag;
+ type Output = Self;
- fn not(self) -> Flag {
+ fn not(self) -> Self {
match self {
- Flag::Active => Flag::Inactive,
- Flag::Inactive => Flag::Active,
+ Self::Active => Self::Inactive,
+ Self::Inactive => Self::Active,
}
}
}
diff --git a/arg_picker/src/value/paths.rs b/arg_picker/src/value/paths.rs
index 403d6cc..d64a09f 100644
--- a/arg_picker/src/value/paths.rs
+++ b/arg_picker/src/value/paths.rs
@@ -117,7 +117,7 @@ pub struct NoPath {
path: PathBuf,
}
-/// Implements common trait impls (From, AsRef, Deref, DerefMut) for a path wrapper type.
+/// Implements common trait impls (`From`, `AsRef`, `Deref`, `DerefMut`) for a path wrapper type.
macro_rules! impl_path_traits {
($type:ident) => {
impl From<PathBuf> for $type {
@@ -227,12 +227,14 @@ impl DerefMut for RecursiveFiles {
impl RecursiveFiles {
/// Returns the number of file paths.
- pub fn len(&self) -> usize {
+ #[must_use]
+ pub const fn len(&self) -> usize {
self.paths.len()
}
/// Returns `true` if there are no file paths.
- pub fn is_empty(&self) -> bool {
+ #[must_use]
+ pub const fn is_empty(&self) -> bool {
self.paths.is_empty()
}
@@ -242,8 +244,17 @@ impl RecursiveFiles {
}
}
-impl From<Vec<RecursiveFiles>> for RecursiveFiles {
- fn from(value: Vec<RecursiveFiles>) -> Self {
+impl<'a> IntoIterator for &'a RecursiveFiles {
+ type Item = &'a PathBuf;
+ type IntoIter = std::slice::Iter<'a, PathBuf>;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.iter()
+ }
+}
+
+impl From<Vec<Self>> for RecursiveFiles {
+ fn from(value: Vec<Self>) -> Self {
Self {
paths: value.into_iter().flat_map(|r| r.paths).collect(),
}
diff --git a/arg_picker/src/value/vec_until.rs b/arg_picker/src/value/vec_until.rs
index 04d87ce..6394cbf 100644
--- a/arg_picker/src/value/vec_until.rs
+++ b/arg_picker/src/value/vec_until.rs
@@ -22,6 +22,7 @@ pub struct VecUntil<T> {
impl<T> VecUntil<T> {
/// Consumes `self` and returns the underlying [`Vec<T>`].
+ #[must_use]
pub fn into_inner(self) -> Vec<T> {
self.inner
}
@@ -29,7 +30,7 @@ impl<T> VecUntil<T> {
impl<T> From<Vec<T>> for VecUntil<T> {
fn from(v: Vec<T>) -> Self {
- VecUntil {
+ Self {
inner: v,
_marker: PhantomData,
}
@@ -72,7 +73,7 @@ where
PickerArgResult::Unparsed => {}
}
}
- PickerArgResult::Parsed(VecUntil {
+ PickerArgResult::Parsed(Self {
inner,
_marker: PhantomData,
})
@@ -97,7 +98,7 @@ where
return positions;
}
- let start = if is_positional { 0 } else { 1 };
+ let start = usize::from(!is_positional);
if start >= positions.len() {
return positions;
}
@@ -118,7 +119,7 @@ where
fn pick(raw_strs: &[&str]) -> PickerArgResult<Self> {
let strs = strip_flag(raw_strs);
let owned: Vec<String> = strs.iter().map(|&s| s.to_string()).collect();
- <VecUntil<T> as MultiPickableWithBoundary>::pick_multi(owned)
+ <Self as MultiPickableWithBoundary>::pick_multi(owned)
}
}