@@ -3031,40 +3031,95 @@ pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
3031
3031
}
3032
3032
3033
3033
/// An iterator that yields nothing.
3034
- #[ unstable( feature="core " , reason = "new addition" ) ]
3034
+ #[ unstable( feature="iter_empty " , reason = "new addition" ) ]
3035
3035
pub struct Empty < T > ( marker:: PhantomData < T > ) ;
3036
3036
3037
+ #[ unstable( feature="iter_empty" , reason = "new addition" ) ]
3037
3038
impl < T > Iterator for Empty < T > {
3038
3039
type Item = T ;
3039
3040
3040
3041
fn next ( & mut self ) -> Option < T > {
3041
3042
None
3042
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
+ }
3043
3080
}
3044
3081
3045
3082
/// Creates an iterator that yields nothing.
3046
- #[ unstable( feature="core " , reason = "new addition" ) ]
3083
+ #[ unstable( feature="iter_empty " , reason = "new addition" ) ]
3047
3084
pub fn empty < T > ( ) -> Empty < T > {
3048
3085
Empty ( marker:: PhantomData )
3049
3086
}
3050
3087
3051
-
3052
3088
/// An iterator that yields an element exactly once.
3053
- #[ unstable( feature="core " , reason = "new addition" ) ]
3089
+ #[ unstable( feature="iter_once " , reason = "new addition" ) ]
3054
3090
pub struct Once < T > {
3055
3091
inner : :: option:: IntoIter < T >
3056
3092
}
3057
3093
3094
+ #[ unstable( feature="iter_once" , reason = "new addition" ) ]
3058
3095
impl < T > Iterator for Once < T > {
3059
3096
type Item = T ;
3060
3097
3061
3098
fn next ( & mut self ) -> Option < T > {
3062
3099
self . inner . next ( )
3063
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
+ }
3064
3119
}
3065
3120
3066
3121
/// Creates an iterator that yields an element exactly once.
3067
- #[ unstable( feature="core " , reason = "new addition" ) ]
3122
+ #[ unstable( feature="iter_once " , reason = "new addition" ) ]
3068
3123
pub fn once < T > ( value : T ) -> Once < T > {
3069
3124
Once { inner : Some ( value) . into_iter ( ) }
3070
3125
}
0 commit comments