#lending-iterator #iterator #lending #iterator-adapter #iterator-extension

gat-lending-iterator

A library for iterators who's items can [mutably] reference the iterator

7 releases

0.1.6 Sep 14, 2024
0.1.5 Dec 9, 2023
0.1.3 Nov 23, 2023
0.1.1 Aug 16, 2023

#208 in Algorithms

Download history 446/week @ 2024-07-30 500/week @ 2024-08-06 277/week @ 2024-08-13 276/week @ 2024-08-20 305/week @ 2024-08-27 369/week @ 2024-09-03 563/week @ 2024-09-10 378/week @ 2024-09-17 253/week @ 2024-09-24 546/week @ 2024-10-01 328/week @ 2024-10-08 324/week @ 2024-10-15 250/week @ 2024-10-22 275/week @ 2024-10-29 465/week @ 2024-11-05 801/week @ 2024-11-12

1,871 downloads per month
Used in 3 crates

MIT license

52KB
1.5K SLoC

Gat Lending Iterator

My concept for what a lending iterator crate should look like. Work in progress.

Most Iterator methods can work as is on LendingIterators, but some wouldn't make sense. Basically any method that needs to look at more than one element at once isn't possible.

Some LendingIterator methods may return something that can act as an Iterator. For example cloned, or map, when the function passed to it returns a value that isn't tied to the lifetime of its input. In these cases, my design choice was to conditionally implement IntoIterator for the adapter.

I've also included an extension trait ToLendingIterator: IntoIterator for iterators that allows turning them into lending iterators in various ways, for example over windows of elements. It's possible I will add more methods to this trait.

methods that behave the same on LendingIterators as they do on Iterators

  • advance_by
  • all
  • any
  • by_ref
  • chain
  • cmp
  • cmp_by
  • count
  • cycle
  • enumerate
  • eq
  • eq_by
  • filter
  • filter_map
  • find
  • find_map
  • flat_map
  • flatten
  • fold
  • for_each
  • fuse
  • ge
  • gt
  • inspect
  • intersperse
  • intersperse_with
  • is_partitioned
  • le
  • lt
  • map
  • map_while
  • ne
  • nth
  • partial_cmp
  • partial_cmp_by
  • position
  • product
  • scan
  • size_hint
  • skip
  • skip_while
  • step_by
  • sum
  • take
  • take_while
  • try_find
  • try_fold
  • try_for_each
  • zip

methods that don't make sense on LendingIterators

  • array_chunks
  • collect
  • collect_into
  • is_sorted
  • is_sorted_by
  • is_sorted_by_key
  • last
  • next_chunk
  • partition
  • partition_in_place
  • peekable
  • try_collect
  • unzip

methods that behave differently on LendingIterators

  • max
  • max_by
  • max_by_key
  • min
  • min_by
  • min_by_key
  • reduce
  • try_reduce

methods that can sometimes be used to convert a LendingIterator into an Iterator

  • cloned
  • copied
  • filter_map
  • flat_map
  • map
  • map_while
  • scan

methods I'm not sure about

  • rev
  • rposition

No runtime deps