Skip to content

Commit fddb73d

Browse files
committed
Add examples for iter::range_step
1 parent dcd4a27 commit fddb73d

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

src/libcore/iter.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,7 +2592,29 @@ pub struct RangeStep<A> {
25922592
rev: bool,
25932593
}
25942594

2595-
/// Return an iterator over the range [start, stop) by `step`. It handles overflow by stopping.
2595+
/// Return an iterator over the range [start, stop) by `step`.
2596+
///
2597+
/// It handles overflow by stopping.
2598+
///
2599+
/// # Examples
2600+
///
2601+
/// ```
2602+
/// use std::iter::range_step;
2603+
///
2604+
/// for i in range_step(0, 10, 2) {
2605+
/// println!("{}", i);
2606+
/// }
2607+
/// ```
2608+
///
2609+
/// This prints:
2610+
///
2611+
/// ```text
2612+
/// 0
2613+
/// 2
2614+
/// 4
2615+
/// 6
2616+
/// 8
2617+
/// ```
25962618
#[inline]
25972619
#[unstable(feature = "core",
25982620
reason = "likely to be replaced by range notation and adapters")]
@@ -2633,7 +2655,30 @@ pub struct RangeStepInclusive<A> {
26332655
done: bool,
26342656
}
26352657

2636-
/// Return an iterator over the range [start, stop] by `step`. It handles overflow by stopping.
2658+
/// Return an iterator over the range [start, stop] by `step`.
2659+
///
2660+
/// It handles overflow by stopping.
2661+
///
2662+
/// # Examples
2663+
///
2664+
/// ```
2665+
/// use std::iter::range_step_inclusive;
2666+
///
2667+
/// for i in range_step_inclusive(0, 10, 2) {
2668+
/// println!("{}", i);
2669+
/// }
2670+
/// ```
2671+
///
2672+
/// This prints:
2673+
///
2674+
/// ```text
2675+
/// 0
2676+
/// 2
2677+
/// 4
2678+
/// 6
2679+
/// 8
2680+
/// 10
2681+
/// ```
26372682
#[inline]
26382683
#[unstable(feature = "core",
26392684
reason = "likely to be replaced by range notation and adapters")]

0 commit comments

Comments
 (0)