Struct Chain

#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct Chain<A, B> { pub(in ::iter::adapters::chain) a: Option<A>, pub(in ::iter::adapters::chain) b: Option<B> }

An iterator that links two iterators together, in a chain.

This struct is created by chain or Iterator::chain. See their documentation for more.

Examples

use std::iter::Chain;
use std::slice::Iter;

let a1 = [1, 2, 3];
let a2 = [4, 5, 6];
let iter: Chain<Iter<'_, _>, Iter<'_, _>> = a1.iter().chain(a2.iter());

Fields

a: Option<A>
b: Option<B>

Implementations

impl<A, B> Chain<A, B>

const fn new(a: A, b: B) -> Chain<A, B>

Trait Implementations

impl<A, B> DoubleEndedIterator for Chain<A, B> where A: DoubleEndedIterator, B: DoubleEndedIterator<Item = A::Item>,

fn next_back(&mut self) -> Option<A::Item>
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
fn nth_back(&mut self, n: usize) -> Option<Self::Item>
fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>
where
    P: FnMut(&Self::Item) -> bool,
fn try_rfold<Acc, F, R>(&mut self, acc: Acc, f: F) -> R
where
    Self: Sized,
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn rfold<Acc, F>(self, acc: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,

impl<A, B> FusedIterator for Chain<A, B> where A: FusedIterator, B: FusedIterator<Item = A::Item>,

impl<A, B> Iterator for Chain<A, B> where A: Iterator, B: Iterator<Item = A::Item>,

type Item = <A as Iterator>::Item;
fn next(&mut self) -> Option<A::Item>
fn count(self) -> usize
fn try_fold<Acc, F, R>(&mut self, acc: Acc, f: F) -> R
where
    Self: Sized,
    F: FnMut(Acc, Self::Item) -> R,
    R: Try<Output = Acc>,
fn fold<Acc, F>(self, acc: Acc, f: F) -> Acc
where
    F: FnMut(Acc, Self::Item) -> Acc,
fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
fn nth(&mut self, n: usize) -> Option<Self::Item>
fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
where
    P: FnMut(&Self::Item) -> bool,
fn last(self) -> Option<A::Item>
fn size_hint(&self) -> (usize, Option<usize>)

impl<A, B> TrustedLen for Chain<A, B> where A: TrustedLen, B: TrustedLen<Item = A::Item>,

impl<A: Clone, B: Clone> Clone for Chain<A, B>

fn clone(&self) -> Chain<A, B>

impl<A: Debug, B: Debug> Debug for Chain<A, B>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<A: Default, B: Default> Default for Chain<A, B>

fn default() -> Self

Creates a Chain from the default values for A and B.

# use core::iter::Chain;
# use core::slice;
# use std::collections::{btree_set, BTreeSet};
# use std::mem;
struct Foo<'a>(Chain<slice::Iter<'a, u8>, btree_set::Iter<'a, u8>>);

let set = BTreeSet::<u8>::new();
let slice: &[u8] = &[];
let mut foo = Foo(slice.iter().chain(set.iter()));

// take requires `Default`
let _: Chain<_, _> = mem::take(&mut foo.0);

Auto Trait Implementations

impl<A, B> Freeze for Chain<A, B> where Option<A>: Freeze, Option<B>: Freeze,

impl<A, B> RefUnwindSafe for Chain<A, B> where Option<A>: RefUnwindSafe, Option<B>: RefUnwindSafe,

impl<A, B> Send for Chain<A, B> where Option<A>: Send, Option<B>: Send,

impl<A, B> Sync for Chain<A, B> where Option<A>: Sync, Option<B>: Sync,

impl<A, B> Unpin for Chain<A, B> where Option<A>: Unpin, Option<B>: Unpin,

impl<A, B> UnsafeUnpin for Chain<A, B> where Option<A>: UnsafeUnpin, Option<B>: UnsafeUnpin,

impl<A, B> UnwindSafe for Chain<A, B> where Option<A>: UnwindSafe, Option<B>: UnwindSafe,

Blanket Implementations

impl<I> IntoIterator for Chain<A, B> where I: Iterator,

type Item = <I as Iterator>::Item;
type IntoIter = I;
fn into_iter(self) -> I

impl<T> Any for Chain<A, B> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Chain<A, B> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Chain<A, B> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Chain<A, B> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Chain<A, B>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for Chain<A, B> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for Chain<A, B>

impl<T, U> Into<U> for Chain<A, B> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Chain<A, B> where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for Chain<A, B> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>