core::iter::successors - Rust
Description: API documentation for the Rust `successors` fn in crate `core`.
Keywords: rust, rustlang, rust-lang, successors

# [−][src]Function core::iter::successors

ⓘImportant traits for Successors<T, F>

### Important traits for Successors<T, F>

`impl<T, F> Iterator for Successors<T, F> where
F: FnMut(&T) -> Option<T>, type Item = T;`

    pub fn successors<T, F>(first: Option<T>, succ: F) -> Successors<T, F> where
        F: FnMut(&T) -> Option<T>,

🔬 This is a nightly-only experimental API. (`iter_unfold` #55977)

Creates a new iterator where each successive item is computed based on the preceding one.

The iterator starts with the given first item (if any) and calls the given `FnMut(&T) -> Option<T>` closure to compute each item’s successor.

    #![feature(iter_unfold)]
    use std::iter::successors;

    let powers_of_10 = successors(Some(1_u16), |n| n.checked_mul(10));
    assert_eq!(powers_of_10.collect::<Vec<_>>(), &[1, 10, 100, 1_000, 10_000]);Run

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)