Skip to content

Commit 63b80bc

Browse files
Merge pull request #261 from brauliobz/grouped_expression
Moved grouped expressions to its own page
2 parents aeeb04d + 9ae7b6f commit 63b80bc

File tree

4 files changed

+40
-22
lines changed

4 files changed

+40
-22
lines changed

src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
- [Path expressions](expressions/path-expr.md)
4646
- [Block expressions](expressions/block-expr.md)
4747
- [Operator expressions](expressions/operator-expr.md)
48+
- [Grouped expressions](expressions/grouped-expr.md)
4849
- [Array and index expressions](expressions/array-expr.md)
4950
- [Tuple and index expressions](expressions/tuple-expr.md)
5051
- [Struct expressions](expressions/struct-expr.md)

src/expressions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ exist in `core::ops` and `core::cmp` with the same names.
252252
[closure expressions]: expressions/closure-expr.html
253253
[enum variant]: expressions/enum-variant-expr.html
254254
[field]: expressions/field-expr.html
255+
[grouped]: expressions/grouped-expr.html
255256
[literals]: expressions/literal-expr.html
256257
[match]: expressions/match-expr.html
257258
[method-call]: expressions/method-call-expr.html
@@ -272,7 +273,6 @@ exist in `core::ops` and `core::cmp` with the same names.
272273
[dereferences]: expressions/operator-expr.html#the-dereference-operator
273274
[dereferencing]: expressions/operator-expr.html#the-dereference-operator
274275
[dereference operator]: expressions/operator-expr.html#the-dereference-operator
275-
[grouped]: expressions/operator-expr.html#grouped-expressions
276276
[lazy boolean]: expressions/operator-expr.html#lazy-boolean-operators
277277
[negation]: expressions/operator-expr.html#negation-operators
278278
[overflow]: expressions/operator-expr.html#overflow

src/expressions/grouped-expr.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Grouped expressions
2+
3+
> **<sup>Syntax</sup>**
4+
> _GroupedExpression_ :
5+
> &nbsp;&nbsp; `(` [_Expression_] `)`
6+
7+
An expression enclosed in parentheses evaluates to the result of the enclosed
8+
expression. Parentheses can be used to explicitly specify evaluation order
9+
within an expression.
10+
11+
An example of a parenthesized expression:
12+
13+
```rust
14+
let x: i32 = 2 + 3 * 4;
15+
let y: i32 = (2 + 3) * 4;
16+
assert_eq!(x, 14);
17+
assert_eq!(y, 20);
18+
```
19+
20+
An example of a necessary use of parentheses is when calling a function pointer
21+
that is a member of a struct:
22+
23+
```rust
24+
# struct A {
25+
# f: fn() -> &'static str
26+
# }
27+
# impl A {
28+
# fn f(&self) -> &'static str {
29+
# "The method f"
30+
# }
31+
# }
32+
# let a = A{f: || "The field f"};
33+
#
34+
assert_eq!( a.f (), "The method f");
35+
assert_eq!((a.f)(), "The field f");
36+
```
37+
38+
[_Expression_]: expressions.html

src/expressions/operator-expr.md

-21
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,6 @@ overflow:
3232
* Using `<<` or `>>` where the right-hand argument is greater than or equal to
3333
the number of bits in the type of the left-hand argument, or is negative.
3434

35-
## Grouped expressions
36-
37-
> **<sup>Syntax</sup>**
38-
> _GroupedExpression_ :
39-
> &nbsp;&nbsp; `(` [_Expression_] `)`
40-
41-
An expression enclosed in parentheses evaluates to the result of the enclosed
42-
expression. Parentheses can be used to explicitly specify evaluation order
43-
within an expression.
44-
45-
This operator cannot be overloaded.
46-
47-
An example of a parenthesized expression:
48-
49-
```rust
50-
let x: i32 = 2 + 3 * 4;
51-
let y: i32 = (2 + 3) * 4;
52-
assert_eq!(x, 14);
53-
assert_eq!(y, 20);
54-
```
55-
5635
## Borrow operators
5736

5837
> **<sup>Syntax</sup>**

0 commit comments

Comments
 (0)