diff --git a/src/expressions/range-expr.md b/src/expressions/range-expr.md index 00db2d989..9b4526b15 100644 --- a/src/expressions/range-expr.md +++ b/src/expressions/range-expr.md @@ -6,6 +6,8 @@ >    | _RangeFromExpr_ >    | _RangeToExpr_ >    | _RangeFullExpr_ +>    | _RangeInclusiveExpr_ +>    | _RangeToInclusiveExpr_ > > _RangeExpr_ : >    [_Expression_] `..` [_Expression_] @@ -18,6 +20,12 @@ > > _RangeFullExpr_ : >    `..` +> +> _RangeInclusiveExpr_ : +>    [_Expression_] `..=` [_Expression_] +> +> _RangeToInclusiveExpr_ : +>    `..=` [_Expression_] The `..` operator will construct an object of one of the `std::ops::Range` (or `core::ops::Range`) variants, according to the following table: @@ -28,14 +36,18 @@ The `..` operator will construct an object of one of the `std::ops::Range` (or | _RangeFromExpr_ | start`..` | [std::ops::RangeFrom] | start ≤ x | | _RangeToExpr_ | `..`end | [std::ops::RangeTo] | x < end | | _RangeFullExpr_ | `..` | [std::ops::RangeFull] | - | +| _RangeInclusiveExpr_ | start`..=`end | [std::ops::RangeInclusive] | start ≤ x ≤ end | +| _RangeToInclusiveExpr_ | `..=`end | [std::ops::RangeToInclusive] | x ≤ end | Examples: ```rust -1..2; // std::ops::Range -3..; // std::ops::RangeFrom -..4; // std::ops::RangeTo -..; // std::ops::RangeFull +let a = 1..2; // std::ops::Range +let a = 3..; // std::ops::RangeFrom +let a = ..4; // std::ops::RangeTo +let a = ..; // std::ops::RangeFull +let a = 1..=2; // std::ops::RangeInclusive +let a = ..=10; // std::ops::RangeToInclusive ``` The following expressions are equivalent. @@ -61,3 +73,6 @@ for i in 1..11 { [std::ops::RangeFrom]: https://doc.rust-lang.org/std/ops/struct.RangeFrom.html [std::ops::RangeTo]: https://doc.rust-lang.org/std/ops/struct.RangeTo.html [std::ops::RangeFull]: https://doc.rust-lang.org/std/ops/struct.RangeFull.html +[std::ops::RangeInclusive]: https://doc.rust-lang.org/std/ops/struct.RangeInclusive.html +[std::ops::RangeToInclusive]: https://doc.rust-lang.org/std/ops/struct.RangeToInclusive.html +