Update on struct expressions (check #32769)
This commit is contained in:
parent
3a0409d291
commit
f396cb42ee
|
@ -2553,7 +2553,7 @@ comma:
|
||||||
|
|
||||||
There are several forms of struct expressions. A _struct expression_
|
There are several forms of struct expressions. A _struct expression_
|
||||||
consists of the [path](#paths) of a [struct item](#structs), followed by
|
consists of the [path](#paths) of a [struct item](#structs), followed by
|
||||||
a brace-enclosed list of one or more comma-separated name-value pairs,
|
a brace-enclosed list of zero or more comma-separated name-value pairs,
|
||||||
providing the field values of a new instance of the struct. A field name
|
providing the field values of a new instance of the struct. A field name
|
||||||
can be any identifier, and is separated from its value expression by a colon.
|
can be any identifier, and is separated from its value expression by a colon.
|
||||||
The location denoted by a struct field is mutable if and only if the
|
The location denoted by a struct field is mutable if and only if the
|
||||||
|
@ -2572,10 +2572,12 @@ The following are examples of struct expressions:
|
||||||
|
|
||||||
```
|
```
|
||||||
# struct Point { x: f64, y: f64 }
|
# struct Point { x: f64, y: f64 }
|
||||||
|
# struct NothingInMe { }
|
||||||
# struct TuplePoint(f64, f64);
|
# struct TuplePoint(f64, f64);
|
||||||
# mod game { pub struct User<'a> { pub name: &'a str, pub age: u32, pub score: usize } }
|
# mod game { pub struct User<'a> { pub name: &'a str, pub age: u32, pub score: usize } }
|
||||||
# struct Cookie; fn some_fn<T>(t: T) {}
|
# struct Cookie; fn some_fn<T>(t: T) {}
|
||||||
Point {x: 10.0, y: 20.0};
|
Point {x: 10.0, y: 20.0};
|
||||||
|
NothingInMe {};
|
||||||
TuplePoint(10.0, 20.0);
|
TuplePoint(10.0, 20.0);
|
||||||
let u = game::User {name: "Joe", age: 35, score: 100_000};
|
let u = game::User {name: "Joe", age: 35, score: 100_000};
|
||||||
some_fn::<Cookie>(Cookie);
|
some_fn::<Cookie>(Cookie);
|
||||||
|
|
Loading…
Reference in New Issue