Skip to content

Instantly share code, notes, and snippets.

@noritada
Created March 21, 2022 10:27
Show Gist options
  • Save noritada/a85cbe86d2436c24d4179e786b8da728 to your computer and use it in GitHub Desktop.
Save noritada/a85cbe86d2436c24d4179e786b8da728 to your computer and use it in GitHub Desktop.
Rust Iterator trait methods call graph

This is a call graph of Iterator methods in Rust, based on Rust 1.59. The purpose of this graph is not to show detailed call relationships, but to visualize roughly what methods other than next() are often reimplemented and what methods are often called internally.

Rustの Iterator のメソッド群のコールグラフです。Rust 1.59に基づいています。 詳細な呼び出し関係を示すためではなく、 next() 以外にどのようなメソッドがよく再実装されているか、どのようなメソッドが内部的によく呼び出されているかを大雑把に可視化する目的で作ったものです。

graph LR
    subgraph I: Iterator
        I::next
        I::size_hint

        I::count
        I::last
        I::advance_by
        I::nth

        I::step_by

        I::chain
        I::zip
	I::intersperse
        I::intersperse_with

        I::map

        I::for_each

        I::filter
        I::filter_map
	I::enumerate
        I::peekable

        I::skip_while
        I::take_while
        I::map_while
        I::skip
        I::take

        I::scan
        I::flat_map
        I::flatten
        I::fuse
        I::inspect
	
        I::by_ref
        I::collect

        I::partition
        %%I::partition_in_place
        I::is_partitioned

        I::try_fold
        I::try_for_each
        I::fold
        I::reduce
        I::try_reduce

        I::all
        I::any
        I::find
        I::find_map
        I::try_find
        I::position
        %%I::rposition

        I::max
        I::min
        I::max_by_key
        I::max_by
        I::min_by_key
        I::min_by

        %%I::rev
        %%I::unzip
        %%I::copied
        %%I::cloned
        %%I::cycle

        I::sum
        I::product

        I::cmp
        I::cmp_by
        I::partial_cmp
        I::partial_cmp_by
        I::eq
        I::eq_by
        I::ne
        I::lt
        I::le
        I::gt
        I::ge

        I::is_sorted
        I::is_sorted_by
        I::is_sorted_by_key
    end

    subgraph StepBy
        StepBy::new
        StepBy::next --> I::next
        StepBy::next --> I::nth
        StepBy::size_hint --> I::size_hint
        StepBy::nth --> I::next
        StepBy::nth --> I::nth
        StepBy::try_fold --> I::next
        StepBy::try_fold --> I::nth
        StepBy::try_fold --> I::try_fold %% FromFn::try_fold
        StepBy::fold --> I::next
        StepBy::fold --> I::nth
        StepBy::fold --> I::fold %% FromFn::fold
    end

    subgraph Chain
        Chain::new
        Chain::next --> I::next
        Chain::count --> I::count
        Chain::try_fold --> I::try_fold
        Chain::fold --> I::fold
        Chain::advance_by --> I::advance_by
        Chain::nth --> I::advance_by
        Chain::nth --> I::next
        Chain::nth --> I::nth
        Chain::find --> I::find
        Chain::last --> I::last
        Chain::size_hint --> I::size_hint
    end

    subgraph Zip
        %% partly implemented using trait `ZipImpl`
        %% specialization ignored
        Zip::new
        Zip::next --> I::next
        Zip::nth --> Zip::next
        Zip::size_hint --> I::size_hint
    end

    subgraph Intersperse
        Intersperse::new --> I::peekable
        Intersperse::next
        Intersperse::fold
        Intersperse::size_hint
    end

    subgraph IntersperseWith
        IntersperseWith::new --> I::peekable
        IntersperseWith::next
        IntersperseWith::fold
        IntersperseWith::size_hint
    end

    subgraph Map
        Map::new
        Map::next --> I::next
        Map::size_hint --> I::size_hint
        Map::try_fold --> I::try_fold
        Map::fold --> I::fold
    end

    subgraph Filter
        Filter::new
        Filter::next --> I::find
        Filter::size_hint --> I::size_hint
        Filter::count --> I::map
        Filter::count --> I::sum
        Filter::try_fold --> I::try_fold
        Filter::fold --> I::fold
    end

    subgraph FilterMap
        FilterMap::new
        FilterMap::next --> I::find_map
        FilterMap::size_hint --> I::size_hint
        FilterMap::try_fold --> I::try_fold
        FilterMap::fold --> I::fold
    end

    subgraph Enumerate
        Enumerate::new
        Enumerate::next --> I::next
        Enumerate::size_hint --> I::size_hint
        Enumerate::nth --> I::nth
        Enumerate::count --> I::count
        Enumerate::try_fold --> I::try_fold
        Enumerate::fold --> I::fold
        Enumerate::advance_by --> I::advance_by
    end

    subgraph Peekable
        Peekable::new
        Peekable::next --> I::next
        Peekable::count --> I::count
        Peekable::nth --> I::nth
        Peekable::last --> I::last
        Peekable::size_hint --> I::size_hint
        Peekable::try_fold --> I::try_fold
        Peekable::fold --> I::fold
        Peekable::peek --> I::next
        Peekable::peek_mut --> I::next
        Peekable::next_if --> Peekable::next
        Peekable::next_if_eq --> Peekable::next_if
    end

    subgraph SkipWhile
        SkipWhile::new
        SkipWhile::next --> I::find
        SkipWhile::size_hint --> I::size_hint
        SkipWhile::try_fold --> SkipWhile::next
        SkipWhile::try_fold --> I::try_fold
        SkipWhile::fold --> SkipWhile::next
        SkipWhile::fold --> I::fold
    end

    subgraph TakeWhile
        TakeWhile::new
        TakeWhile::next --> I::next
        TakeWhile::size_hint --> I::size_hint
        TakeWhile::try_fold --> I::try_fold
        TakeWhile::fold --> I::try_fold
    end

    subgraph MapWhile
        MapWhile::new
        MapWhile::next --> I::next
        MapWhile::size_hint --> I::size_hint
        MapWhile::try_fold --> I::try_fold
        MapWhile::fold --> I::try_fold
    end

    subgraph Skip
        Skip::new
        Skip::next --> I::nth
        Skip::next --> I::next
        Skip::nth --> I::nth
        Skip::count --> I::nth
        Skip::count --> I::count
        Skip::last --> I::nth
        Skip::last --> I::last
        Skip::size_hint --> I::size_hint
        Skip::try_fold --> I::nth
        Skip::try_fold --> I::try_fold
        Skip::fold --> I::nth
        Skip::fold --> I::fold
        Skip::advance_by --> I::advance_by
    end

    subgraph Take
        Take::new
        Take::next --> I::next
        Take::nth --> I::nth
        Take::size_hint --> I::size_hint
        Take::try_fold --> I::try_fold
        Take::fold --> I::try_fold
    end

    subgraph Scan
        Scan::new
        Scan::next --> I::next
        Scan::size_hint --> I::size_hint
        Scan::try_fold --> I::try_fold
        Scan::fold --> I::try_fold
    end

    subgraph FlatMap
        FlatMap::new
        FlatMap::next --> I::find_map
        FlatMap::size_hint --> I::size_hint
        FlatMap::try_fold --> I::try_fold
        FlatMap::fold --> I::fold
    end

    subgraph Flatten
        Flatten::new
        Flatten::next --> I::next
        Flatten::size_hint --> I::size_hint
        Flatten::try_fold --> I::try_fold
        Flatten::fold --> I::fold
    end

    subgraph Fuse
        %% partly implemented using trait `FuseImpl`
        %% specialization ignored
        Fuse::new
        Fuse::next --> I::next
        Fuse::nth --> I::next
        Fuse::last --> I::last
        Fuse::count --> I::count
        Fuse::size_hint --> I::size_hint
        Fuse::try_fold --> I::try_fold
        Fuse::fold --> I::fold
        Fuse::find --> I::find
    end

    subgraph Inspect
        Inspect::new
        Inspect::next --> I::next
        Inspect::size_hint --> I::size_hint
        Inspect::try_fold --> I::try_fold
        Inspect::fold --> I::fold
    end

    subgraph Inspect
        Inspect::new
        Inspect::next --> I::next
        Inspect::size_hint --> I::size_hint
        Inspect::try_fold --> I::try_fold
        Inspect::fold --> I::fold
    end

    subgraph B: FromIterator
        B::from_iter
    end

    subgraph S: Sum
        S::sum
    end

    subgraph P: Product
        P::product
    end

    I::count --> I::fold
    I::last --> I::fold
    I::advance_by --> I::next
    I::nth --> I::advance_by
    I::nth --> I::next

    I::step_by --> StepBy::new

    I::chain --> Chain::new
    I::zip --> Zip::new
    I::intersperse --> Intersperse::new
    I::intersperse_with --> IntersperseWith::new

    I::map --> Map::new

    I::for_each --> I::fold

    I::filter --> Filter::new
    I::filter_map --> FilterMap::new
    I::enumerate --> Enumerate::new
    I::peekable --> Peekable::new

    I::skip_while --> SkipWhile::new
    I::take_while --> TakeWhile::new
    I::map_while --> MapWhile::new
    I::skip --> Skip::new
    I::take --> Take::new

    I::scan --> Scan::new
    I::flat_map --> FlatMap::new
    I::flatten --> Flatten::new
    I::fuse --> Fuse::new
    I::inspect --> Inspect::new

    I::collect --> B::from_iter

    I::partition --> I::fold
    %%I::partition_in_place --> I::find
    %%I::partition_in_place --> I::rfind
    I::is_partitioned --> I::all
    I::is_partitioned --> I::any

    I::try_fold --> I::next
    I::try_for_each --> I::try_fold
    I::fold --> I::next
    I::reduce --> I::next
    I::reduce --> I::fold
    I::try_reduce --> I::next
    I::try_reduce --> I::try_fold

    I::all --> I::try_fold
    I::any --> I::try_fold
    I::find --> I::try_fold
    I::find_map --> I::try_fold
    I::try_find --> I::try_fold
    I::position --> I::try_fold
    %%I::rposition --> I::try_rfold

    I::max --> I::max_by
    I::min --> I::min_by
    I::max_by_key --> I::map
    I::max_by_key --> I::max_by %% Map::max_by
    I::max_by --> I::reduce
    I::min_by_key --> I::map
    I::min_by_key --> I::min_by %% Map::min_by
    I::min_by --> I::reduce

    %%I::rev --> Rev::new
    %%I::unzip --> Extend::extend
    %%I::copied --> Copied::new
    %%I::cloned --> Cloned::new
    %%I::cycle --> Cycle::new

    I::sum --> S::sum
    I::product --> P::product

    I::cmp --> I::cmp_by
    I::cmp_by --> I::next
    I::partial_cmp --> I::partial_cmp_by
    I::partial_cmp_by --> I::next
    I::eq --> I::eq_by
    I::eq_by --> I::next
    I::ne --> I::eq
    I::lt --> I::partial_cmp
    I::le --> I::partial_cmp
    I::gt --> I::partial_cmp
    I::ge --> I::partial_cmp

    I::is_sorted --> I::is_sorted_by
    I::is_sorted_by --> I::next
    I::is_sorted_by --> I::all
    I::is_sorted_by_key --> I::map
    I::is_sorted_by_key --> I::is_sorted %% Map::is_sorted

    Intersperse::next --> Peekable::peek
    Intersperse::next --> Peekable::next
    Intersperse::fold --> Peekable::next
    Intersperse::fold --> Peekable::fold
    Intersperse::size_hint --> Peekable::size_hint

    IntersperseWith::next --> Peekable::peek
    IntersperseWith::next --> Peekable::next
    IntersperseWith::fold --> Peekable::next
    IntersperseWith::fold --> Peekable::fold
    IntersperseWith::size_hint --> Peekable::size_hint
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment