Skip to content

Commit

Permalink
Update 0000-std-iter-once.md
Browse files Browse the repository at this point in the history
  • Loading branch information
XMPPwocky committed Apr 10, 2015
1 parent b30ad71 commit 5c2aaa0
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions text/0000-std-iter-once.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

# Summary

Add a `once` function to `std::iter` to construct an iterator yielding a given value one time.
Add a `once` function to `std::iter` to construct an iterator yielding a given value one time, and an `empty` function to construct an iterator yielding no values.

# Motivation

This is a common task when working with iterators. Currently, this can be done in many ways, most of which are unergonomic, do not work for all types (e.g. requiring Copy/Clone), or both. `once` is simple to implement, simple to use, and simple to understand.
This is a common task when working with iterators. Currently, this can be done in many ways, most of which are unergonomic, do not work for all types (e.g. requiring Copy/Clone), or both. `once` and `empty` are simple to implement, simple to use, and simple to understand.

# Detailed design

Expand All @@ -24,7 +24,19 @@ pub fn once<T>(x: T) -> Once<T> {
}
```

The `Once` wrapper struct exists to allow future backwards-compatible changes, and hide the implementation.
`empty` is similar:

```rust
pub struct Empty<T>(std::option::IntoIter<T>);

pub fn empty<T>(x: T) -> Empty<T> {
Empty(
None.into_iter()
)
}
```

These wrapper structs exist to allow future backwards-compatible changes, and hide the implementation.

# Drawbacks

Expand Down

0 comments on commit 5c2aaa0

Please sign in to comment.