@@ -3030,6 +3030,100 @@ pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
30303030 Repeat { element : elt}
30313031}
30323032
3033+ /// An iterator that yields nothing.
3034+ #[ unstable( feature="iter_empty" , reason = "new addition" ) ]
3035+ pub struct Empty < T > ( marker:: PhantomData < T > ) ;
3036+
3037+ #[ unstable( feature="iter_empty" , reason = "new addition" ) ]
3038+ impl < T > Iterator for Empty < T > {
3039+ type Item = T ;
3040+
3041+ fn next ( & mut self ) -> Option < T > {
3042+ None
3043+ }
3044+
3045+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
3046+ ( 0 , Some ( 0 ) )
3047+ }
3048+ }
3049+
3050+ #[ unstable( feature="iter_empty" , reason = "new addition" ) ]
3051+ impl < T > DoubleEndedIterator for Empty < T > {
3052+ fn next_back ( & mut self ) -> Option < T > {
3053+ None
3054+ }
3055+ }
3056+
3057+ #[ unstable( feature="iter_empty" , reason = "new addition" ) ]
3058+ impl < T > ExactSizeIterator for Empty < T > {
3059+ fn len ( & self ) -> usize {
3060+ 0
3061+ }
3062+ }
3063+
3064+ // not #[derive] because that adds a Clone bound on T,
3065+ // which isn't necessary.
3066+ #[ unstable( feature="iter_empty" , reason = "new addition" ) ]
3067+ impl < T > Clone for Empty < T > {
3068+ fn clone ( & self ) -> Empty < T > {
3069+ Empty ( marker:: PhantomData )
3070+ }
3071+ }
3072+
3073+ // not #[derive] because that adds a Default bound on T,
3074+ // which isn't necessary.
3075+ #[ unstable( feature="iter_empty" , reason = "new addition" ) ]
3076+ impl < T > Default for Empty < T > {
3077+ fn default ( ) -> Empty < T > {
3078+ Empty ( marker:: PhantomData )
3079+ }
3080+ }
3081+
3082+ /// Creates an iterator that yields nothing.
3083+ #[ unstable( feature="iter_empty" , reason = "new addition" ) ]
3084+ pub fn empty < T > ( ) -> Empty < T > {
3085+ Empty ( marker:: PhantomData )
3086+ }
3087+
3088+ /// An iterator that yields an element exactly once.
3089+ #[ unstable( feature="iter_once" , reason = "new addition" ) ]
3090+ pub struct Once < T > {
3091+ inner : :: option:: IntoIter < T >
3092+ }
3093+
3094+ #[ unstable( feature="iter_once" , reason = "new addition" ) ]
3095+ impl < T > Iterator for Once < T > {
3096+ type Item = T ;
3097+
3098+ fn next ( & mut self ) -> Option < T > {
3099+ self . inner . next ( )
3100+ }
3101+
3102+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
3103+ self . inner . size_hint ( )
3104+ }
3105+ }
3106+
3107+ #[ unstable( feature="iter_once" , reason = "new addition" ) ]
3108+ impl < T > DoubleEndedIterator for Once < T > {
3109+ fn next_back ( & mut self ) -> Option < T > {
3110+ self . inner . next_back ( )
3111+ }
3112+ }
3113+
3114+ #[ unstable( feature="iter_once" , reason = "new addition" ) ]
3115+ impl < T > ExactSizeIterator for Once < T > {
3116+ fn len ( & self ) -> usize {
3117+ self . inner . len ( )
3118+ }
3119+ }
3120+
3121+ /// Creates an iterator that yields an element exactly once.
3122+ #[ unstable( feature="iter_once" , reason = "new addition" ) ]
3123+ pub fn once < T > ( value : T ) -> Once < T > {
3124+ Once { inner : Some ( value) . into_iter ( ) }
3125+ }
3126+
30333127/// Functions for lexicographical ordering of sequences.
30343128///
30353129/// Lexicographical ordering through `<`, `<=`, `>=`, `>` requires
0 commit comments