Skip to content

Commit 7e9ff16

Browse files
committed
Implement additional traits for iter::Once/Empty
Also changed the stability feature on them. Implement Default for iter::Once/Empty Implement additional traits for iter::Once/Empty
1 parent c63d795 commit 7e9ff16

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

src/libcore/iter.rs

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,40 +3031,95 @@ pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
30313031
}
30323032

30333033
/// An iterator that yields nothing.
3034-
#[unstable(feature="core", reason = "new addition")]
3034+
#[unstable(feature="iter_empty", reason = "new addition")]
30353035
pub struct Empty<T>(marker::PhantomData<T>);
30363036

3037+
#[unstable(feature="iter_empty", reason = "new addition")]
30373038
impl<T> Iterator for Empty<T> {
30383039
type Item = T;
30393040

30403041
fn next(&mut self) -> Option<T> {
30413042
None
30423043
}
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+
}
30433080
}
30443081

30453082
/// Creates an iterator that yields nothing.
3046-
#[unstable(feature="core", reason = "new addition")]
3083+
#[unstable(feature="iter_empty", reason = "new addition")]
30473084
pub fn empty<T>() -> Empty<T> {
30483085
Empty(marker::PhantomData)
30493086
}
30503087

3051-
30523088
/// An iterator that yields an element exactly once.
3053-
#[unstable(feature="core", reason = "new addition")]
3089+
#[unstable(feature="iter_once", reason = "new addition")]
30543090
pub struct Once<T> {
30553091
inner: ::option::IntoIter<T>
30563092
}
30573093

3094+
#[unstable(feature="iter_once", reason = "new addition")]
30583095
impl<T> Iterator for Once<T> {
30593096
type Item = T;
30603097

30613098
fn next(&mut self) -> Option<T> {
30623099
self.inner.next()
30633100
}
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+
}
30643119
}
30653120

30663121
/// Creates an iterator that yields an element exactly once.
3067-
#[unstable(feature="core", reason = "new addition")]
3122+
#[unstable(feature="iter_once", reason = "new addition")]
30683123
pub fn once<T>(value: T) -> Once<T> {
30693124
Once { inner: Some(value).into_iter() }
30703125
}

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ mod core {
167167
pub use marker;
168168
pub use option;
169169
pub use iter;
170+
pub use default;
170171
}
171172

172173
#[doc(hidden)]

src/libcoretest/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#![feature(step_by)]
2525
#![feature(slice_patterns)]
2626
#![feature(float_from_str_radix)]
27+
#![feature(iter_empty)]
28+
#![feature(iter_once)]
2729

2830
extern crate core;
2931
extern crate test;

0 commit comments

Comments
 (0)