Skip to main content

core/iter/traits/
collect.rs

1#[cfg(not(feature = "ferrocene_subset"))]
2use super::TrustedLen;
3
4/// Conversion from an [`Iterator`].
5///
6/// By implementing `FromIterator` for a type, you define how it will be
7/// created from an iterator. This is common for types which describe a
8/// collection of some kind.
9///
10/// If you want to create a collection from the contents of an iterator, the
11/// [`Iterator::collect()`] method is preferred. However, when you need to
12/// specify the container type, [`FromIterator::from_iter()`] can be more
13/// readable than using a turbofish (e.g. `::<Vec<_>>()`). See the
14/// [`Iterator::collect()`] documentation for more examples of its use.
15///
16/// See also: [`IntoIterator`].
17///
18/// # Examples
19///
20/// Basic usage:
21///
22/// ```
23/// let five_fives = std::iter::repeat(5).take(5);
24///
25/// let v = Vec::from_iter(five_fives);
26///
27/// assert_eq!(v, vec![5, 5, 5, 5, 5]);
28/// ```
29///
30/// Using [`Iterator::collect()`] to implicitly use `FromIterator`:
31///
32/// ```
33/// let five_fives = std::iter::repeat(5).take(5);
34///
35/// let v: Vec<i32> = five_fives.collect();
36///
37/// assert_eq!(v, vec![5, 5, 5, 5, 5]);
38/// ```
39///
40/// Using [`FromIterator::from_iter()`] as a more readable alternative to
41/// [`Iterator::collect()`]:
42///
43/// ```
44/// use std::collections::VecDeque;
45/// let first = (0..10).collect::<VecDeque<i32>>();
46/// let second = VecDeque::from_iter(0..10);
47///
48/// assert_eq!(first, second);
49/// ```
50///
51/// Implementing `FromIterator` for your type:
52///
53/// ```
54/// // A sample collection, that's just a wrapper over Vec<T>
55/// #[derive(Debug)]
56/// struct MyCollection(Vec<i32>);
57///
58/// // Let's give it some methods so we can create one and add things
59/// // to it.
60/// impl MyCollection {
61///     fn new() -> MyCollection {
62///         MyCollection(Vec::new())
63///     }
64///
65///     fn add(&mut self, elem: i32) {
66///         self.0.push(elem);
67///     }
68/// }
69///
70/// // and we'll implement FromIterator
71/// impl FromIterator<i32> for MyCollection {
72///     fn from_iter<I: IntoIterator<Item=i32>>(iter: I) -> Self {
73///         let mut c = MyCollection::new();
74///
75///         for i in iter {
76///             c.add(i);
77///         }
78///
79///         c
80///     }
81/// }
82///
83/// // Now we can make a new iterator...
84/// let iter = (0..5).into_iter();
85///
86/// // ... and make a MyCollection out of it
87/// let c = MyCollection::from_iter(iter);
88///
89/// assert_eq!(c.0, vec![0, 1, 2, 3, 4]);
90///
91/// // collect works too!
92///
93/// let iter = (0..5).into_iter();
94/// let c: MyCollection = iter.collect();
95///
96/// assert_eq!(c.0, vec![0, 1, 2, 3, 4]);
97/// ```
98#[stable(feature = "rust1", since = "1.0.0")]
99#[rustc_on_unimplemented(
100    on(
101        Self = "&[{A}]",
102        message = "a slice of type `{Self}` cannot be built since we need to store the elements somewhere",
103        label = "try explicitly collecting into a `Vec<{A}>`",
104    ),
105    on(
106        all(A = "{integer}", any(Self = "&[{integral}]",)),
107        message = "a slice of type `{Self}` cannot be built since we need to store the elements somewhere",
108        label = "try explicitly collecting into a `Vec<{A}>`",
109    ),
110    on(
111        Self = "[{A}]",
112        message = "a slice of type `{Self}` cannot be built since `{Self}` has no definite size",
113        label = "try explicitly collecting into a `Vec<{A}>`",
114    ),
115    on(
116        all(A = "{integer}", any(Self = "[{integral}]",)),
117        message = "a slice of type `{Self}` cannot be built since `{Self}` has no definite size",
118        label = "try explicitly collecting into a `Vec<{A}>`",
119    ),
120    on(
121        Self = "[{A}; _]",
122        message = "an array of type `{Self}` cannot be built directly from an iterator",
123        label = "try collecting into a `Vec<{A}>`, then using `.try_into()`",
124    ),
125    on(
126        all(A = "{integer}", any(Self = "[{integral}; _]",)),
127        message = "an array of type `{Self}` cannot be built directly from an iterator",
128        label = "try collecting into a `Vec<{A}>`, then using `.try_into()`",
129    ),
130    message = "a value of type `{Self}` cannot be built from an iterator \
131               over elements of type `{A}`",
132    label = "value of type `{Self}` cannot be built from `std::iter::Iterator<Item={A}>`"
133)]
134#[rustc_diagnostic_item = "FromIterator"]
135pub trait FromIterator<A>: Sized {
136    /// Creates a value from an iterator.
137    ///
138    /// See the [module-level documentation] for more.
139    ///
140    /// [module-level documentation]: crate::iter
141    ///
142    /// # Examples
143    ///
144    /// ```
145    /// let five_fives = std::iter::repeat(5).take(5);
146    ///
147    /// let v = Vec::from_iter(five_fives);
148    ///
149    /// assert_eq!(v, vec![5, 5, 5, 5, 5]);
150    /// ```
151    #[stable(feature = "rust1", since = "1.0.0")]
152    #[rustc_diagnostic_item = "from_iter_fn"]
153    fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self;
154}
155
156/// Conversion into an [`Iterator`].
157///
158/// By implementing `IntoIterator` for a type, you define how it will be
159/// converted to an iterator. This is common for types which describe a
160/// collection of some kind.
161///
162/// One benefit of implementing `IntoIterator` is that your type will [work
163/// with Rust's `for` loop syntax](crate::iter#for-loops-and-intoiterator).
164///
165/// See also: [`FromIterator`].
166///
167/// # Examples
168///
169/// Basic usage:
170///
171/// ```
172/// let v = [1, 2, 3];
173/// let mut iter = v.into_iter();
174///
175/// assert_eq!(Some(1), iter.next());
176/// assert_eq!(Some(2), iter.next());
177/// assert_eq!(Some(3), iter.next());
178/// assert_eq!(None, iter.next());
179/// ```
180/// Implementing `IntoIterator` for your type:
181///
182/// ```
183/// // A sample collection, that's just a wrapper over Vec<T>
184/// #[derive(Debug)]
185/// struct MyCollection(Vec<i32>);
186///
187/// // Let's give it some methods so we can create one and add things
188/// // to it.
189/// impl MyCollection {
190///     fn new() -> MyCollection {
191///         MyCollection(Vec::new())
192///     }
193///
194///     fn add(&mut self, elem: i32) {
195///         self.0.push(elem);
196///     }
197/// }
198///
199/// // and we'll implement IntoIterator
200/// impl IntoIterator for MyCollection {
201///     type Item = i32;
202///     type IntoIter = std::vec::IntoIter<Self::Item>;
203///
204///     fn into_iter(self) -> Self::IntoIter {
205///         self.0.into_iter()
206///     }
207/// }
208///
209/// // Now we can make a new collection...
210/// let mut c = MyCollection::new();
211///
212/// // ... add some stuff to it ...
213/// c.add(0);
214/// c.add(1);
215/// c.add(2);
216///
217/// // ... and then turn it into an Iterator:
218/// for (i, n) in c.into_iter().enumerate() {
219///     assert_eq!(i as i32, n);
220/// }
221/// ```
222///
223/// It is common to use `IntoIterator` as a trait bound. This allows
224/// the input collection type to change, so long as it is still an
225/// iterator. Additional bounds can be specified by restricting on
226/// `Item`:
227///
228/// ```rust
229/// fn collect_as_strings<T>(collection: T) -> Vec<String>
230/// where
231///     T: IntoIterator,
232///     T::Item: std::fmt::Debug,
233/// {
234///     collection
235///         .into_iter()
236///         .map(|item| format!("{item:?}"))
237///         .collect()
238/// }
239/// ```
240#[rustc_diagnostic_item = "IntoIterator"]
241#[rustc_on_unimplemented(
242    on(
243        Self = "core::ops::range::RangeTo<Idx>",
244        label = "if you meant to iterate until a value, add a starting value",
245        note = "`..end` is a `RangeTo`, which cannot be iterated on; you might have meant to have a \
246              bounded `Range`: `0..end`"
247    ),
248    on(
249        Self = "core::ops::range::RangeToInclusive<Idx>",
250        label = "if you meant to iterate until a value (including it), add a starting value",
251        note = "`..=end` is a `RangeToInclusive`, which cannot be iterated on; you might have meant \
252              to have a bounded `RangeInclusive`: `0..=end`"
253    ),
254    on(
255        Self = "[]",
256        label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
257    ),
258    on(Self = "&[]", label = "`{Self}` is not an iterator; try calling `.iter()`"),
259    on(
260        Self = "alloc::vec::Vec<T, A>",
261        label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
262    ),
263    on(Self = "&str", label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"),
264    on(
265        Self = "alloc::string::String",
266        label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"
267    ),
268    on(
269        Self = "{integral}",
270        note = "if you want to iterate between `start` until a value `end`, use the exclusive range \
271              syntax `start..end` or the inclusive range syntax `start..=end`"
272    ),
273    on(
274        Self = "{float}",
275        note = "if you want to iterate between `start` until a value `end`, use the exclusive range \
276              syntax `start..end` or the inclusive range syntax `start..=end`"
277    ),
278    label = "`{Self}` is not an iterator",
279    message = "`{Self}` is not an iterator"
280)]
281#[rustc_skip_during_method_dispatch(array, boxed_slice)]
282#[stable(feature = "rust1", since = "1.0.0")]
283#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
284pub const trait IntoIterator {
285    /// The type of the elements being iterated over.
286    #[rustc_diagnostic_item = "IntoIteratorItem"]
287    #[stable(feature = "rust1", since = "1.0.0")]
288    type Item;
289
290    /// Which kind of iterator are we turning this into?
291    #[stable(feature = "rust1", since = "1.0.0")]
292    type IntoIter: Iterator<Item = Self::Item>;
293
294    /// Creates an iterator from a value.
295    ///
296    /// See the [module-level documentation] for more.
297    ///
298    /// [module-level documentation]: crate::iter
299    ///
300    /// # Examples
301    ///
302    /// ```
303    /// let v = [1, 2, 3];
304    /// let mut iter = v.into_iter();
305    ///
306    /// assert_eq!(Some(1), iter.next());
307    /// assert_eq!(Some(2), iter.next());
308    /// assert_eq!(Some(3), iter.next());
309    /// assert_eq!(None, iter.next());
310    /// ```
311    #[lang = "into_iter"]
312    #[stable(feature = "rust1", since = "1.0.0")]
313    fn into_iter(self) -> Self::IntoIter;
314}
315
316#[stable(feature = "rust1", since = "1.0.0")]
317#[rustc_const_unstable(feature = "const_iter", issue = "92476")]
318impl<I: [const] Iterator> const IntoIterator for I {
319    type Item = I::Item;
320    type IntoIter = I;
321
322    #[inline]
323    fn into_iter(self) -> I {
324        self
325    }
326}
327
328/// Extend a collection with the contents of an iterator.
329///
330/// Iterators produce a series of values, and collections can also be thought
331/// of as a series of values. The `Extend` trait bridges this gap, allowing you
332/// to extend a collection by including the contents of that iterator. When
333/// extending a collection with an already existing key, that entry is updated
334/// or, in the case of collections that permit multiple entries with equal
335/// keys, that entry is inserted.
336///
337/// # Examples
338///
339/// Basic usage:
340///
341/// ```
342/// // You can extend a String with some chars:
343/// let mut message = String::from("The first three letters are: ");
344///
345/// message.extend(&['a', 'b', 'c']);
346///
347/// assert_eq!("abc", &message[29..32]);
348/// ```
349///
350/// Implementing `Extend`:
351///
352/// ```
353/// // A sample collection, that's just a wrapper over Vec<T>
354/// #[derive(Debug)]
355/// struct MyCollection(Vec<i32>);
356///
357/// // Let's give it some methods so we can create one and add things
358/// // to it.
359/// impl MyCollection {
360///     fn new() -> MyCollection {
361///         MyCollection(Vec::new())
362///     }
363///
364///     fn add(&mut self, elem: i32) {
365///         self.0.push(elem);
366///     }
367/// }
368///
369/// // since MyCollection has a list of i32s, we implement Extend for i32
370/// impl Extend<i32> for MyCollection {
371///
372///     // This is a bit simpler with the concrete type signature: we can call
373///     // extend on anything which can be turned into an Iterator which gives
374///     // us i32s. Because we need i32s to put into MyCollection.
375///     fn extend<T: IntoIterator<Item=i32>>(&mut self, iter: T) {
376///
377///         // The implementation is very straightforward: loop through the
378///         // iterator, and add() each element to ourselves.
379///         for elem in iter {
380///             self.add(elem);
381///         }
382///     }
383/// }
384///
385/// let mut c = MyCollection::new();
386///
387/// c.add(5);
388/// c.add(6);
389/// c.add(7);
390///
391/// // let's extend our collection with three more numbers
392/// c.extend(vec![1, 2, 3]);
393///
394/// // we've added these elements onto the end
395/// assert_eq!("MyCollection([5, 6, 7, 1, 2, 3])", format!("{c:?}"));
396/// ```
397#[stable(feature = "rust1", since = "1.0.0")]
398pub trait Extend<A> {
399    /// Extends a collection with the contents of an iterator.
400    ///
401    /// As this is the only required method for this trait, the [trait-level] docs
402    /// contain more details.
403    ///
404    /// [trait-level]: Extend
405    ///
406    /// # Examples
407    ///
408    /// ```
409    /// // You can extend a String with some chars:
410    /// let mut message = String::from("abc");
411    ///
412    /// message.extend(['d', 'e', 'f'].iter());
413    ///
414    /// assert_eq!("abcdef", &message);
415    /// ```
416    #[stable(feature = "rust1", since = "1.0.0")]
417    fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T);
418
419    /// Extends a collection with exactly one element.
420    #[unstable(feature = "extend_one", issue = "72631")]
421    fn extend_one(&mut self, item: A) {
422        self.extend(Some(item));
423    }
424
425    /// Reserves capacity in a collection for the given number of additional elements.
426    ///
427    /// The default implementation does nothing.
428    #[unstable(feature = "extend_one", issue = "72631")]
429    fn extend_reserve(&mut self, additional: usize) {
430        let _ = additional;
431    }
432
433    /// Extends a collection with one element, without checking there is enough capacity for it.
434    ///
435    /// # Safety
436    ///
437    /// **For callers:** This must only be called when we know the collection has enough capacity
438    /// to contain the new item, for example because we previously called `extend_reserve`.
439    ///
440    /// **For implementors:** For a collection to unsafely rely on this method's safety precondition (that is,
441    /// invoke UB if they are violated), it must implement `extend_reserve` correctly. In other words,
442    /// callers may assume that if they `extend_reserve`ed enough space they can call this method.
443    // This method is for internal usage only. It is only on the trait because of specialization's limitations.
444    #[unstable(feature = "extend_one_unchecked", issue = "none")]
445    #[doc(hidden)]
446    unsafe fn extend_one_unchecked(&mut self, item: A)
447    where
448        Self: Sized,
449    {
450        self.extend_one(item);
451    }
452}
453
454#[stable(feature = "extend_for_unit", since = "1.28.0")]
455#[cfg(not(feature = "ferrocene_subset"))]
456impl Extend<()> for () {
457    fn extend<T: IntoIterator<Item = ()>>(&mut self, iter: T) {
458        iter.into_iter().for_each(drop)
459    }
460    fn extend_one(&mut self, _item: ()) {}
461}
462
463/// This trait is implemented for tuples up to twelve items long. The `impl`s for
464/// 1- and 3- through 12-ary tuples were stabilized after 2-tuples, in 1.85.0.
465#[doc(fake_variadic)] // the other implementations are below.
466#[stable(feature = "extend_for_tuple", since = "1.56.0")]
467#[cfg(not(feature = "ferrocene_subset"))]
468impl<T, ExtendT> Extend<(T,)> for (ExtendT,)
469where
470    ExtendT: Extend<T>,
471{
472    /// Allows to `extend` a tuple of collections that also implement `Extend`.
473    ///
474    /// See also: [`Iterator::unzip`]
475    ///
476    /// # Examples
477    /// ```
478    /// // Example given for a 2-tuple, but 1- through 12-tuples are supported
479    /// let mut tuple = (vec![0], vec![1]);
480    /// tuple.extend([(2, 3), (4, 5), (6, 7)]);
481    /// assert_eq!(tuple.0, [0, 2, 4, 6]);
482    /// assert_eq!(tuple.1, [1, 3, 5, 7]);
483    ///
484    /// // also allows for arbitrarily nested tuples as elements
485    /// let mut nested_tuple = (vec![1], (vec![2], vec![3]));
486    /// nested_tuple.extend([(4, (5, 6)), (7, (8, 9))]);
487    ///
488    /// let (a, (b, c)) = nested_tuple;
489    /// assert_eq!(a, [1, 4, 7]);
490    /// assert_eq!(b, [2, 5, 8]);
491    /// assert_eq!(c, [3, 6, 9]);
492    /// ```
493    fn extend<I: IntoIterator<Item = (T,)>>(&mut self, iter: I) {
494        self.0.extend(iter.into_iter().map(|t| t.0));
495    }
496
497    fn extend_one(&mut self, item: (T,)) {
498        self.0.extend_one(item.0)
499    }
500
501    fn extend_reserve(&mut self, additional: usize) {
502        self.0.extend_reserve(additional)
503    }
504
505    unsafe fn extend_one_unchecked(&mut self, item: (T,)) {
506        // SAFETY: the caller guarantees all preconditions.
507        unsafe { self.0.extend_one_unchecked(item.0) }
508    }
509}
510
511/// This implementation turns an iterator of tuples into a tuple of types which implement
512/// [`Default`] and [`Extend`].
513///
514/// This is similar to [`Iterator::unzip`], but is also composable with other [`FromIterator`]
515/// implementations:
516///
517/// ```rust
518/// # fn main() -> Result<(), core::num::ParseIntError> {
519/// let string = "1,2,123,4";
520///
521/// // Example given for a 2-tuple, but 1- through 12-tuples are supported
522/// let (numbers, lengths): (Vec<_>, Vec<_>) = string
523///     .split(',')
524///     .map(|s| s.parse().map(|n: u32| (n, s.len())))
525///     .collect::<Result<_, _>>()?;
526///
527/// assert_eq!(numbers, [1, 2, 123, 4]);
528/// assert_eq!(lengths, [1, 1, 3, 1]);
529/// # Ok(()) }
530/// ```
531#[doc(fake_variadic)] // the other implementations are below.
532#[stable(feature = "from_iterator_for_tuple", since = "1.79.0")]
533#[cfg(not(feature = "ferrocene_subset"))]
534impl<T, ExtendT> FromIterator<(T,)> for (ExtendT,)
535where
536    ExtendT: Default + Extend<T>,
537{
538    fn from_iter<Iter: IntoIterator<Item = (T,)>>(iter: Iter) -> Self {
539        let mut res = ExtendT::default();
540        res.extend(iter.into_iter().map(|t| t.0));
541        (res,)
542    }
543}
544
545/// An implementation of [`extend`](Extend::extend) that calls `extend_one` or
546/// `extend_one_unchecked` for each element of the iterator.
547#[cfg(not(feature = "ferrocene_subset"))]
548fn default_extend<ExtendT, I, T>(collection: &mut ExtendT, iter: I)
549where
550    ExtendT: Extend<T>,
551    I: IntoIterator<Item = T>,
552{
553    // Specialize on `TrustedLen` and call `extend_one_unchecked` where
554    // applicable.
555    trait SpecExtend<I> {
556        fn extend(&mut self, iter: I);
557    }
558
559    // Extracting these to separate functions avoid monomorphising the closures
560    // for every iterator type.
561    fn extender<ExtendT, T>(collection: &mut ExtendT) -> impl FnMut(T) + use<'_, ExtendT, T>
562    where
563        ExtendT: Extend<T>,
564    {
565        move |item| collection.extend_one(item)
566    }
567
568    unsafe fn unchecked_extender<ExtendT, T>(
569        collection: &mut ExtendT,
570    ) -> impl FnMut(T) + use<'_, ExtendT, T>
571    where
572        ExtendT: Extend<T>,
573    {
574        // SAFETY: we make sure that there is enough space at the callsite of
575        // this function.
576        move |item| unsafe { collection.extend_one_unchecked(item) }
577    }
578
579    impl<ExtendT, I, T> SpecExtend<I> for ExtendT
580    where
581        ExtendT: Extend<T>,
582        I: Iterator<Item = T>,
583    {
584        default fn extend(&mut self, iter: I) {
585            let (lower_bound, _) = iter.size_hint();
586            if lower_bound > 0 {
587                self.extend_reserve(lower_bound);
588            }
589
590            iter.for_each(extender(self))
591        }
592    }
593
594    impl<ExtendT, I, T> SpecExtend<I> for ExtendT
595    where
596        ExtendT: Extend<T>,
597        I: TrustedLen<Item = T>,
598    {
599        fn extend(&mut self, iter: I) {
600            let (lower_bound, upper_bound) = iter.size_hint();
601            if lower_bound > 0 {
602                self.extend_reserve(lower_bound);
603            }
604
605            if upper_bound.is_none() {
606                // We cannot reserve more than `usize::MAX` items, and this is likely to go out of memory anyway.
607                iter.for_each(extender(self))
608            } else {
609                // SAFETY: We reserve enough space for the `size_hint`, and the iterator is
610                // `TrustedLen` so its `size_hint` is exact.
611                iter.for_each(unsafe { unchecked_extender(self) })
612            }
613        }
614    }
615
616    SpecExtend::extend(collection, iter.into_iter());
617}
618
619// Implements `Extend` and `FromIterator` for tuples with length larger than one.
620macro_rules! impl_extend_tuple {
621    ($(($ty:tt, $extend_ty:tt, $index:tt)),+) => {
622        #[doc(hidden)]
623        #[stable(feature = "extend_for_tuple", since = "1.56.0")]
624        #[cfg(not(feature = "ferrocene_subset"))]
625        impl<$($ty,)+ $($extend_ty,)+> Extend<($($ty,)+)> for ($($extend_ty,)+)
626        where
627            $($extend_ty: Extend<$ty>,)+
628        {
629            fn extend<T: IntoIterator<Item = ($($ty,)+)>>(&mut self, iter: T) {
630                default_extend(self, iter)
631            }
632
633            fn extend_one(&mut self, item: ($($ty,)+)) {
634                $(self.$index.extend_one(item.$index);)+
635            }
636
637            fn extend_reserve(&mut self, additional: usize) {
638                $(self.$index.extend_reserve(additional);)+
639            }
640
641            unsafe fn extend_one_unchecked(&mut self, item: ($($ty,)+)) {
642                // SAFETY: Those are our safety preconditions, and we correctly forward `extend_reserve`.
643                unsafe {
644                    $(self.$index.extend_one_unchecked(item.$index);)+
645                }
646            }
647        }
648
649        #[doc(hidden)]
650        #[stable(feature = "from_iterator_for_tuple", since = "1.79.0")]
651        #[cfg(not(feature = "ferrocene_subset"))]
652        impl<$($ty,)+ $($extend_ty,)+> FromIterator<($($ty,)+)> for ($($extend_ty,)+)
653        where
654            $($extend_ty: Default + Extend<$ty>,)+
655        {
656            fn from_iter<Iter: IntoIterator<Item = ($($ty,)+)>>(iter: Iter) -> Self {
657                let mut res = Self::default();
658                res.extend(iter);
659                res
660            }
661        }
662    };
663}
664
665impl_extend_tuple!((A, ExA, 0), (B, ExB, 1));
666impl_extend_tuple!((A, ExA, 0), (B, ExB, 1), (C, ExC, 2));
667impl_extend_tuple!((A, ExA, 0), (B, ExB, 1), (C, ExC, 2), (D, ExD, 3));
668impl_extend_tuple!((A, ExA, 0), (B, ExB, 1), (C, ExC, 2), (D, ExD, 3), (E, ExE, 4));
669impl_extend_tuple!((A, ExA, 0), (B, ExB, 1), (C, ExC, 2), (D, ExD, 3), (E, ExE, 4), (F, ExF, 5));
670impl_extend_tuple!(
671    (A, ExA, 0),
672    (B, ExB, 1),
673    (C, ExC, 2),
674    (D, ExD, 3),
675    (E, ExE, 4),
676    (F, ExF, 5),
677    (G, ExG, 6)
678);
679impl_extend_tuple!(
680    (A, ExA, 0),
681    (B, ExB, 1),
682    (C, ExC, 2),
683    (D, ExD, 3),
684    (E, ExE, 4),
685    (F, ExF, 5),
686    (G, ExG, 6),
687    (H, ExH, 7)
688);
689impl_extend_tuple!(
690    (A, ExA, 0),
691    (B, ExB, 1),
692    (C, ExC, 2),
693    (D, ExD, 3),
694    (E, ExE, 4),
695    (F, ExF, 5),
696    (G, ExG, 6),
697    (H, ExH, 7),
698    (I, ExI, 8)
699);
700impl_extend_tuple!(
701    (A, ExA, 0),
702    (B, ExB, 1),
703    (C, ExC, 2),
704    (D, ExD, 3),
705    (E, ExE, 4),
706    (F, ExF, 5),
707    (G, ExG, 6),
708    (H, ExH, 7),
709    (I, ExI, 8),
710    (J, ExJ, 9)
711);
712impl_extend_tuple!(
713    (A, ExA, 0),
714    (B, ExB, 1),
715    (C, ExC, 2),
716    (D, ExD, 3),
717    (E, ExE, 4),
718    (F, ExF, 5),
719    (G, ExG, 6),
720    (H, ExH, 7),
721    (I, ExI, 8),
722    (J, ExJ, 9),
723    (K, ExK, 10)
724);
725impl_extend_tuple!(
726    (A, ExA, 0),
727    (B, ExB, 1),
728    (C, ExC, 2),
729    (D, ExD, 3),
730    (E, ExE, 4),
731    (F, ExF, 5),
732    (G, ExG, 6),
733    (H, ExH, 7),
734    (I, ExI, 8),
735    (J, ExJ, 9),
736    (K, ExK, 10),
737    (L, ExL, 11)
738);