From 355f35536d642fa8c9df9fe2d0b2290375749253 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 20 Feb 2015 17:11:06 -0500 Subject: [PATCH] Add examples for iter::range_step --- src/libcore/iter.rs | 49 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 8fb10b5b2dc..2d50bbb6413 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -2592,7 +2592,29 @@ pub struct RangeStep { rev: bool, } -/// Return an iterator over the range [start, stop) by `step`. It handles overflow by stopping. +/// Return an iterator over the range [start, stop) by `step`. +/// +/// It handles overflow by stopping. +/// +/// # Examples +/// +/// ``` +/// use std::iter::range_step; +/// +/// for i in range_step(0, 10, 2) { +/// println!("{}", i); +/// } +/// ``` +/// +/// This prints: +/// +/// ```text +/// 0 +/// 2 +/// 4 +/// 6 +/// 8 +/// ``` #[inline] #[unstable(feature = "core", reason = "likely to be replaced by range notation and adapters")] @@ -2633,7 +2655,30 @@ pub struct RangeStepInclusive { done: bool, } -/// Return an iterator over the range [start, stop] by `step`. It handles overflow by stopping. +/// Return an iterator over the range [start, stop] by `step`. +/// +/// It handles overflow by stopping. +/// +/// # Examples +/// +/// ``` +/// use std::iter::range_step_inclusive; +/// +/// for i in range_step_inclusive(0, 10, 2) { +/// println!("{}", i); +/// } +/// ``` +/// +/// This prints: +/// +/// ```text +/// 0 +/// 2 +/// 4 +/// 6 +/// 8 +/// 10 +/// ``` #[inline] #[unstable(feature = "core", reason = "likely to be replaced by range notation and adapters")]