@@ -153,6 +153,7 @@ pub trait FromIterator<A>: Sized {
153153}
154154
155155// 为同时实现 Default 和 Extend 的类型实现 FromIterator
156+ #[ cfg( feature = "specialization" ) ]
156157#[ stable( feature = "from_iter_default" , since = "CURRENT_RUSTC_VERSION" ) ]
157158impl < A , T : Default + Extend < A > > FromIterator < A > for T {
158159 #[ rustc_diagnostic_item = "from_iter_default" ]
@@ -646,40 +647,40 @@ macro_rules! spec_tuple_impl {
646647 }
647648 }
648649
649- /// This implementation turns an iterator of tuples into a tuple of types which implement
650- /// [`Default`] and [`Extend`].
651- ///
652- /// This is similar to [`Iterator::unzip`], but is also composable with other [`FromIterator`]
653- /// implementations:
654- ///
655- /// ```rust
656- /// # fn main() -> Result<(), core::num::ParseIntError> {
657- /// let string = "1,2,123,4";
658- ///
659- /// // Example given for a 2-tuple, but 1- through 12-tuples are supported
660- /// let (numbers, lengths): (Vec<_>, Vec<_>) = string
661- /// .split(',')
662- /// .map(|s| s.parse().map(|n: u32| (n, s.len())))
663- /// .collect::<Result<_, _>>()?;
664- ///
665- /// assert_eq!(numbers, [1, 2, 123, 4]);
666- /// assert_eq!(lengths, [1, 1, 3, 1]);
667- /// # Ok(()) }
668- /// ```
669- #[ $meta]
670- $( #[ $doctext] ) ?
671- #[ stable( feature = "from_iterator_for_tuple" , since = "1.79.0" ) ]
672- impl <$( $ty_names, ) * $( $extend_ty_names, ) * > FromIterator <( $( $extend_ty_names, ) * ) > for ( $( $ty_names, ) * )
673- where
674- $( $ty_names: Default + Extend <$extend_ty_names>, ) *
675- {
676- fn from_iter<Iter : IntoIterator <Item = ( $( $extend_ty_names, ) * ) >>( iter: Iter ) -> Self {
677- let mut res = <( $( $ty_names, ) * ) >:: default ( ) ;
678- res. extend( iter) ;
650+ // // / This implementation turns an iterator of tuples into a tuple of types which implement
651+ // // / [`Default`] and [`Extend`].
652+ // // /
653+ // // / This is similar to [`Iterator::unzip`], but is also composable with other [`FromIterator`]
654+ // // / implementations:
655+ // // /
656+ // // / ```rust
657+ // // / # fn main() -> Result<(), core::num::ParseIntError> {
658+ // // / let string = "1,2,123,4";
659+ // // /
660+ // // / // Example given for a 2-tuple, but 1- through 12-tuples are supported
661+ // // / let (numbers, lengths): (Vec<_>, Vec<_>) = string
662+ // // / .split(',')
663+ // // / .map(|s| s.parse().map(|n: u32| (n, s.len())))
664+ // // / .collect::<Result<_, _>>()?;
665+ // // /
666+ // // / assert_eq!(numbers, [1, 2, 123, 4]);
667+ // // / assert_eq!(lengths, [1, 1, 3, 1]);
668+ // // / # Ok(()) }
669+ // // / ```
670+ // #[$meta]
671+ // $(#[$doctext])?
672+ // #[stable(feature = "from_iterator_for_tuple", since = "1.79.0")]
673+ // impl<$($ty_names,)* $($extend_ty_names,)*> FromIterator<($($extend_ty_names,)*)> for ($($ty_names,)*)
674+ // where
675+ // $($ty_names: Default + Extend<$extend_ty_names>,)*
676+ // {
677+ // fn from_iter<Iter: IntoIterator<Item = ($($extend_ty_names,)*)>>(iter: Iter) -> Self {
678+ // let mut res = <($($ty_names,)*)>::default();
679+ // res.extend(iter);
679680
680- res
681- }
682- }
681+ // res
682+ // }
683+ // }
683684
684685 } ;
685686}
0 commit comments