Skip to content

Commit 5c2aaa0

Browse files
committed
Update 0000-std-iter-once.md
1 parent b30ad71 commit 5c2aaa0

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

text/0000-std-iter-once.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
# Summary
66

7-
Add a `once` function to `std::iter` to construct an iterator yielding a given value one time.
7+
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.
88

99
# Motivation
1010

11-
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.
11+
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.
1212

1313
# Detailed design
1414

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

27-
The `Once` wrapper struct exists to allow future backwards-compatible changes, and hide the implementation.
27+
`empty` is similar:
28+
29+
```rust
30+
pub struct Empty<T>(std::option::IntoIter<T>);
31+
32+
pub fn empty<T>(x: T) -> Empty<T> {
33+
Empty(
34+
None.into_iter()
35+
)
36+
}
37+
```
38+
39+
These wrapper structs exist to allow future backwards-compatible changes, and hide the implementation.
2840

2941
# Drawbacks
3042

0 commit comments

Comments
 (0)