From 3ce16dbc2f179e7080b61c26698b1fdd3ef75c4c Mon Sep 17 00:00:00 2001 From: Niklas Elsbrock Date: Fri, 20 Jun 2025 16:55:22 +0200 Subject: [PATCH] doc: rewrite links to be more specific --- src/lib.rs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7305f11..4c8c9bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,16 +1,16 @@ #![no_std] #![warn(missing_docs)] -//! This crate provides [`accumulate()`], an iterator adaptor that accumulates the elements from the +//! This crate provides [`accumulate`], an iterator adaptor that accumulates the elements from the //! base iterator using the provided closure. //! -//! [`accumulate()`] takes two arguments: an initial value, and a closure with two arguments: +//! [`accumulate`] takes two arguments: an initial value, and a closure with two arguments: //! an 'accumulator', and an element. //! //! The initial value is the value the accumulator will have when the closure is first called. -//! On each call to [`next()`], the closure is executed with the current accumulator and the element -//! yielded by the upstream iterator. The return value of the closure is then set as the new value -//! of the accumulator and returned to the caller. +//! On each call to [`Iterator::next`], the closure is executed with the current accumulator and the +//! element yielded by the upstream iterator. The return value of the closure is then set as the new +//! value of the accumulator and returned to the caller. //! //! Since the accumulated value needs to be both stored as the accumulator *and* returned to the //! caller, the accumulator type must implement [`Copy`]. If you want to operate on non-copyable @@ -18,14 +18,14 @@ //! //! The returned iterator is **not** fused and it is not specified what happens when the base //! iterator returns [`None`]. -//! If you want a fused iterator, use [`fuse()`]. +//! If you want a fused iterator, use [`Iterator::fuse`]. //! -//! # Differences to [`fold()`] +//! # Differences to [`Iterator::fold`] //! -//! In principle, [`accumulate()`] is similar to [`fold()`]. However, instead of returning the final -//! accumulated result, it returns an iterator that yields the current value of the accumulator for -//! each iteration. In other words, the last element yielded by [`accumulate()`] is what would have -//! been returned by [`fold()`] if it had been used instead. +//! In principle, [`accumulate`] is similar to [`Iterator::fold`]. However, instead of returning +//! the final accumulated result, it returns an iterator that yields the current value of the +//! accumulator for each iteration. In other words, the last element yielded by [`accumulate`] is +//! what would have been returned by [`Iterator::fold`] if it had been used instead. //! //! # Examples //! @@ -43,10 +43,7 @@ //! assert_eq!(iter.next(), None); //! ``` //! -//! [`accumulate()`]: IterAccumulate::accumulate -//! [`fold()`]: Iterator::fold -//! [`next()`]: Iterator::next -//! [`fuse()`]: Iterator::fuse +//! [`accumulate`]: IterAccumulate::accumulate use core::fmt; @@ -111,7 +108,7 @@ where } } -/// An [`Iterator`] blanket implementation that provides the [`accumulate()`](Self::accumulate) +/// An [`Iterator`] blanket implementation that provides the [`accumulate`](Self::accumulate) /// function. pub trait IterAccumulate: Iterator { /// Creates an iterator adaptor that accumulates the elements from the base iterator using the