Структура MatchIndices

#![allow(unused)]
fn main() {
pub struct MatchIndices<'a, P>(/* приватные поля */)
where
    P: Pattern;
}

Создается методом match_indices.

Реализации трейтов

impl<'a, P> Clone for MatchIndices<'a, P>

#![allow(unused)]
fn main() {
where
    P: Pattern,
    <P as Pattern>::Searcher<'a>: Clone,

}
ФункцияСинтаксисПримерНазначение
clonefn clone(&self) -> MatchIndices<'a, P> ⓘlet cloned = match_indices.clone();Возвращает копию значения
clone_fromfn clone_from(&mut self, source: &Self)match_indices.clone_from(&other);Выполняет копирующее присваивание из source

impl<'a, P> Debug for MatchIndices<'a, P>

#![allow(unused)]
fn main() {
where
    P: Pattern,
    <P as Pattern>::Searcher<'a>: Debug,

}
ФункцияСинтаксисПримерНазначение
fmtfn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>println!("{:?}", match_indices);Форматирует значение с помощью заданного форматтера

impl<'a, P> DoubleEndedIterator for MatchIndices<'a, P>

#![allow(unused)]
fn main() {
where
    P: Pattern,
    <P as Pattern>::Searcher<'a>: DoubleEndedSearcher<'a>,

}
ФункцияСинтаксисПримерНазначение
next_backfn next_back(&mut self) -> Option<(usize, &'a str)>let last_match = match_indices.next_back();Удаляет и возвращает элемент с конца итератора
advance_back_byfn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>>match_indices.advance_back_by(2)?;🔬 Перемещает итератор с конца на n элементов
nth_back (с версии 1.37.0)fn nth_back(&mut self, n: usize) -> Option<Self::Item>let second_last = match_indices.nth_back(1);Возвращает n-й элемент с конца итератора
try_rfold (с версии 1.27.0)fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R`let result = match_indices.try_rfold(vec![],mut v, (i, s)
rfold (с версии 1.27.0)fn rfold<B, F>(self, init: B, f: F) -> B`let total_len = match_indices.rfold(0,acc, (_, s)
rfind (с версии 1.27.0)fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>`let last_long = match_indices.rfind((_, s)

impl<'a, P> Iterator for MatchIndices<'a, P>

#![allow(unused)]
fn main() {
where
    P: Pattern,

}
ФункцияСинтаксисПримерНазначение
type Itemtype Item = (usize, &'a str)-Тип элементов, по которым выполняется итерация (пара: индекс и срез строки)
nextfn next(&mut self) -> Option<(usize, &'a str)>let first_match = match_indices.next();Перемещает итератор и возвращает следующее значение
next_chunkfn next_chunk<const N: usize>(&mut self) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>let chunk = match_indices.next_chunk::<3>()?;🔬 Возвращает массив, содержащий следующие N значений
size_hintfn size_hint(&self) -> (usize, Option<usize>)let hint = match_indices.size_hint();Возвращает границы оставшейся длины итератора
countfn count(self) -> usizelet total_matches = match_indices.count();Подсчитывает количество итераций и возвращает его
lastfn last(self) -> Option<Self::Item>let last_match = match_indices.last();Возвращает последний элемент итератора
advance_byfn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>match_indices.advance_by(2)?;🔬 Перемещает итератор на n элементов
nthfn nth(&mut self, n: usize) -> Option<Self::Item>let third_match = match_indices.nth(2);Возвращает n-й элемент итератора
step_by (с версии 1.28.0)fn step_by(self, step: usize) -> StepBy<Self> ⓘlet every_second = match_indices.step_by(2);Создает итератор с заданным шагом
chainfn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter> ⓘlet combined = match_indices.chain(other_matches);Объединяет два итератора в последовательный
zipfn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter> ⓘlet paired = match_indices.zip(other_data);"Объединяет" два итератора в итератор пар
interspersefn intersperse(self, separator: Self::Item) -> Intersperse<Self> ⓘlet with_sep = match_indices.intersperse((0, ""));🔬 Помещает копию separator между элементами
intersperse_withfn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G> ⓘ`let with_sep = match_indices.intersperse_with(
mapfn map<B, F>(self, f: F) -> Map<Self, F> ⓘ`let indices = match_indices.map((i, _)
for_eachfn for_each<F>(self, f: F)`match_indices.for_each((i, s)
filterfn filter<P>(self, predicate: P) -> Filter<Self, P> ⓘ`let long_matches = match_indices.filter((_, s)
filter_mapfn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> ⓘ`let lengths = match_indices.filter_map((i, s)
enumeratefn enumerate(self) -> Enumerate<Self> ⓘfor (j, (i, s)) in match_indices.enumerate() { ... }Добавляет индекс к каждому элементу
peekablefn peekable(self) -> Peekable<Self> ⓘlet peekable = match_indices.peekable();Создает итератор с возможностью просмотра следующего элемента
skip_whilefn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> ⓘ`let skipped = match_indices.skip_while((i, _)
take_whilefn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> ⓘ`let taken = match_indices.take_while((i, _)
map_while (с версии 1.57.0)fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P> ⓘ`let mapped = match_indices.map_while((i, s)
skipfn skip(self, n: usize) -> Skip<Self> ⓘlet skipped = match_indices.skip(3);Пропускает первые n элементов
takefn take(self, n: usize) -> Take<Self> ⓘlet taken = match_indices.take(5);Берет первые n элементов
scanfn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F> ⓘ`let scanned = match_indices.scan(vec![],state, (i, s)
flat_mapfn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> ⓘ`let chars = match_indices.flat_map((_, s)
flatten (с версии 1.29.0)fn flatten(self) -> Flatten<Self> ⓘlet flattened = match_indices.flatten();Сглаживает вложенную структуру
map_windowsfn map_windows<F, R, const N: usize>(self, f: F) -> MapWindows<Self, F, N> ⓘ`let windows = match_indices.map_windows::<_, _, 2>(arr
fusefn fuse(self) -> Fuse<Self> ⓘlet fused = match_indices.fuse();Создает итератор, завершающийся после первого None
inspectfn inspect<F>(self, f: F) -> Inspect<Self, F> ⓘ`let inspected = match_indices.inspect((i, s)
by_reffn by_ref(&mut self) -> &mut Selflet part = match_indices.by_ref().take(5).collect::<Vec<_>>();Создает адаптер "по ссылке" для итератора
collectfn collect<B>(self) -> Blet vec: Vec<(usize, &str)> = match_indices.collect();Преобразует итератор в коллекцию
try_collectfn try_collect<B>(&mut self) -> <<Self::Item as Try>::Residual as Residual<B>>::TryTypelet result: Result<Vec<(usize, &str)>, _> = match_indices.try_collect();🔬 Преобразует итератор в коллекцию с обработкой ошибок
collect_intofn collect_into<E>(self, collection: &mut E) -> &mut Elet mut vec = Vec::new(); match_indices.collect_into(&mut vec);🔬 Собирает все элементы в коллекцию
partitionfn partition<B, F>(self, f: F) -> (B, B)`let (early, late): (Vec<>, Vec<>) = match_indices.partition((i, _)
partition_in_placefn partition_in_place<'a, T, P>(self, predicate: P) -> usize`let count = match_indices.partition_in_place((i, _)
is_partitionedfn is_partitioned<P>(self, predicate: P) -> bool`let partitioned = match_indices.is_partitioned((i, _)
try_fold (с версии 1.27.0)fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R`let total_len = match_indices.try_fold(0,acc, (_, s)
try_for_each (с версии 1.27.0)fn try_for_each<F, R>(&mut self, f: F) -> R`let result: Result<(), _> = match_indices.try_for_each((i, s)
foldfn fold<B, F>(self, init: B, f: F) -> B`let total_len = match_indices.fold(0,acc, (_, s)
reduce (с версии 1.51.0)fn reduce<F>(self, f: F) -> Option<Self::Item>`let longest = match_indices.reduce(a, b
try_reducefn try_reduce<R>(&mut self, f: impl FnMut(Self::Item, Self::Item) -> R) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryType`let result: Result<Option<(usize, &str)>, _> = match_indices.try_reduce(a, b
allfn all<F>(&mut self, f: F) -> bool`let all_long = match_indices.all((_, s)
anyfn any<F>(&mut self, f: F) -> bool`let has_empty = match_indices.any((_, s)
findfn find<P>(&mut self, predicate: P) -> Option<Self::Item>`let first_long = match_indices.find((_, s)
find_map (с версии 1.30.0)fn find_map<B, F>(&mut self, f: F) -> Option<B>`let first_num = match_indices.find_map((i, s)
try_findfn try_find<R>(&mut self, f: impl FnMut(&Self::Item) -> R) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryType`let result: Result<Option<(usize, &str)>, _> = match_indices.try_find((_, s)
positionfn position<P>(&mut self, predicate: P) -> Option<usize>`let pos = match_indices.position((_, s)
rpositionfn rposition<P>(&mut self, predicate: P) -> Option<usize>`let pos = match_indices.rposition((_, s)
maxfn max(self) -> Option<Self::Item>let longest = match_indices.max();Возвращает максимальный элемент (лексикографически)
minfn min(self) -> Option<Self::Item>let shortest = match_indices.min();Возвращает минимальный элемент (лексикографически)
max_by_key (с версии 1.6.0)fn max_by_key<B, F>(self, f: F) -> Option<Self::Item>`let latest = match_indices.max_by_key((i, _)
max_by (с версии 1.15.0)fn max_by<F>(self, compare: F) -> Option<Self::Item>`let longest = match_indices.max_by(a, b
min_by_key (с версии 1.6.0)fn min_by_key<B, F>(self, f: F) -> Option<Self::Item>`let earliest = match_indices.min_by_key((i, _)
min_by (с версии 1.15.0)fn min_by<F>(self, compare: F) -> Option<Self::Item>`let shortest = match_indices.min_by(a, b
revfn rev(self) -> Rev<Self> ⓘlet reversed = match_indices.rev();Изменяет направление итератора
unzipfn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)let (indices, matches): (Vec<usize>, Vec<&str>) = match_indices.unzip();Преобразует итератор пар в пару контейнеров
copied (с версии 1.36.0)fn copied<'a, T>(self) -> Copied<Self> ⓘlet copied = match_indices.copied();Создает итератор, который копирует все элементы
clonedfn cloned<'a, T>(self) -> Cloned<Self> ⓘlet cloned = match_indices.cloned();Создает итератор, который клонирует все элементы
cyclefn cycle(self) -> Cycle<Self> ⓘlet cycled = match_indices.cycle();Бесконечно повторяет итератор
array_chunksfn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N> ⓘfor chunk in match_indices.array_chunks::<3>() { ... }🔬 Возвращает итератор по N элементов за раз
sum (с версии 1.11.0)fn sum<S>(self) -> S`let total_len: usize = match_indices.map((_, s)
product (с версии 1.11.0)fn product<P>(self) -> P`let product: usize = match_indices.map((_, s)
cmp (с версии 1.5.0)fn cmp<I>(self, other: I) -> Orderinglet ordering = match_indices.cmp(other_matches);Лексикографически сравнивает элементы с другими
cmp_byfn cmp_by<I, F>(self, other: I, cmp: F) -> Ordering`let ordering = match_indices.cmp_by(other_matches,a, b
partial_cmp (с версии 1.5.0)fn partial_cmp<I>(self, other: I) -> Option<Ordering>let ordering = match_indices.partial_cmp(other_matches);Частично сравнивает элементы с другими
partial_cmp_byfn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>`let ordering = match_indices.partial_cmp_by(other_matches,a, b
eq (с версии 1.5.0)fn eq<I>(self, other: I) -> boollet equal = match_indices.eq(other_matches);Проверяет равенство элементов с другими
eq_byfn eq_by<I, F>(self, other: I, eq: F) -> bool`let equal = match_indices.eq_by(other_matches,a, b
ne (с версии 1.5.0)fn ne<I>(self, other: I) -> boollet not_equal = match_indices.ne(other_matches);Проверяет неравенство элементов с другими
lt (с версии 1.5.0)fn lt<I>(self, other: I) -> boollet less = match_indices.lt(other_matches);Проверяет, меньше ли элементы, чем другие
le (с версии 1.5.0)fn le<I>(self, other: I) -> boollet less_or_equal = match_indices.le(other_matches);Проверяет, меньше или равны ли элементы
gt (с версии 1.5.0)fn gt<I>(self, other: I) -> boollet greater = match_indices.gt(other_matches);Проверяет, больше ли элементы, чем другие
ge (с версии 1.5.0)fn ge<I>(self, other: I) -> boollet greater_or_equal = match_indices.ge(other_matches);Проверяет, больше или равны ли элементы
is_sorted (с версии 1.82.0)fn is_sorted(self) -> boollet sorted = match_indices.is_sorted();Проверяет, отсортированы ли элементы (по индексу)
is_sorted_by (с версии 1.82.0)fn is_sorted_by<F>(self, compare: F) -> bool`let sorted = match_indices.is_sorted_by(a, b
is_sorted_by_key (с версии 1.82.0)fn is_sorted_by_key<F, K>(self, f: F) -> bool`let sorted = match_indices.is_sorted_by_key((i, _)

impl<'a, P> FusedIterator for MatchIndices<'a, P> (с версии 1.26.0)

#![allow(unused)]
fn main() {
where
    P: Pattern,

}

Автоматические реализации трейтов

#![allow(unused)]
fn main() {
impl<'a, P> Freeze for MatchIndices<'a, P>
where
    <P as Pattern>::Searcher<'a>: Freeze,
}
#![allow(unused)]
fn main() {
impl<'a, P> RefUnwindSafe for MatchIndices<'a, P>
where
    <P as Pattern>::Searcher<'a>: RefUnwindSafe,
}
#![allow(unused)]
fn main() {
impl<'a, P> Send for MatchIndices<'a, P>
where
    <P as Pattern>::Searcher<'a>: Send,
}
#![allow(unused)]
fn main() {
impl<'a, P> Sync for MatchIndices<'a, P>
where
    <P as Pattern>::Searcher<'a>: Sync,
}
#![allow(unused)]
fn main() {
impl<'a, P> Unpin for MatchIndices<'a, P>
where
    <P as Pattern>::Searcher<'a>: Unpin,
}
#![allow(unused)]
fn main() {
impl<'a, P> UnwindSafe for MatchIndices<'a, P>
where
    <P as Pattern>::Searcher<'a>: UnwindSafe,
}

Общие реализации

#![allow(unused)]
fn main() {
impl<T> Any for T
where
    T: 'static + ?Sized,
}
#![allow(unused)]
fn main() {
impl<T> Borrow<T> for T
where
    T: ?Sized,
}
#![allow(unused)]
fn main() {
impl<T> BorrowMut<T> for T
where
    T: ?Sized,
}
#![allow(unused)]
fn main() {
impl<T> CloneToUninit for T
where
    T: Clone,
}
#![allow(unused)]
fn main() {
impl<T> From<T> for T
}
#![allow(unused)]
fn main() {
impl<T, U> Into<U> for T
where
    U: From<T>,
}
#![allow(unused)]
fn main() {
impl<I> IntoIterator for I
where
    I: Iterator,
}
#![allow(unused)]
fn main() {
impl<T> ToOwned for T
where
    T: Clone,
}
#![allow(unused)]
fn main() {
impl<T, U> TryFrom<U> for T
where
    U: Into<T>,
}
#![allow(unused)]
fn main() {
impl<T, U> TryInto<U> for T
where
    U: TryFrom<T>,
}

Обозначения:

  • 🔬 - экспериментальное API, доступное только в ночных сборках
  • - обозначение, что функция возвращает итератор
  • P: Pattern - шаблон для поиска
  • <P as Pattern>::Searcher<'a> - тип искателя для шаблона