Skip to content

Commit a5cbb19

Browse files
committed
Use IntoIterator instead of inherent methods
1 parent 1fdbb1e commit a5cbb19

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Symbol {
6262
/// Possible modifiers for this symbol.
6363
pub fn modifiers(&self) -> impl Iterator<Item = &str> + '_ {
6464
self.variants()
65-
.flat_map(|(m, _)| m.to_iter())
65+
.flat_map(|(m, _)| m.into_iter())
6666
.collect::<std::collections::BTreeSet<_>>()
6767
.into_iter()
6868
}

src/shared.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ macro_rules! declare_types {
4545
};
4646
}
4747

48+
use std::ops::Deref;
49+
4850
pub(crate) use declare_types;
4951

5052
/// A set of modifiers.
@@ -64,7 +66,7 @@ impl<S: Default> Default for ModifierSet<S> {
6466
}
6567
}
6668

67-
impl<S: std::ops::Deref<Target = str>> ModifierSet<S> {
69+
impl<S: Deref<Target = str>> ModifierSet<S> {
6870
/// Convert the underlying string to a slice.
6971
pub fn as_deref(&self) -> ModifierSet<&str> {
7072
ModifierSet(&self.0)
@@ -103,7 +105,7 @@ impl<S: std::ops::Deref<Target = str>> ModifierSet<S> {
103105

104106
/// Iterate over the list of modifiers in an arbitrary order.
105107
pub fn iter(&self) -> impl Iterator<Item = &str> {
106-
self.0.split('.').filter(|s| !s.is_empty())
108+
self.into_iter()
107109
}
108110

109111
/// Whether the set contains the modifier `m`.
@@ -152,9 +154,22 @@ impl<S: std::ops::Deref<Target = str>> ModifierSet<S> {
152154
}
153155
}
154156

155-
impl<'a> ModifierSet<&'a str> {
156-
/// Iterate over the list of modifiers with the original lifetime.
157-
pub fn to_iter(self) -> impl Iterator<Item = &'a str> {
158-
self.0.split('.').filter(|s| !s.is_empty())
157+
impl<'a, S: Deref<Target = str>> IntoIterator for &'a ModifierSet<S> {
158+
type Item = &'a str;
159+
type IntoIter = std::str::Split<'a, char>;
160+
161+
/// Iterate over the list of modifiers in an arbitrary order.
162+
fn into_iter(self) -> Self::IntoIter {
163+
self.0.split('.')
164+
}
165+
}
166+
167+
impl<'a> IntoIterator for ModifierSet<&'a str> {
168+
type Item = &'a str;
169+
type IntoIter = std::str::Split<'a, char>;
170+
171+
/// Iterate over the list of modifiers in an arbitrary order.
172+
fn into_iter(self) -> Self::IntoIter {
173+
self.0.split('.')
159174
}
160175
}

0 commit comments

Comments
 (0)