Skip to content

Commit 380d918

Browse files
committed
---
yaml --- r: 206797 b: refs/heads/beta c: 797d8e2 h: refs/heads/master i: 206795: fce9e9b v: v3
1 parent 5854750 commit 380d918

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2929
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3030
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3131
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
32-
refs/heads/beta: 457aed7ca003d7cbef2cda8360ad9b8b5bb83650
32+
refs/heads/beta: 797d8e28695a9f349a3155958e06c527250bdac9
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3535
refs/heads/tmp: 579e31929feff51dcaf8d444648eff8de735f91a

branches/beta/src/doc/trpl/structs.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,22 @@ println!("length is {} inches", integer_length);
177177
As you can see here, you can extract the inner integer type through a
178178
destructuring `let`, just as with regular tuples. In this case, the
179179
`let Inches(integer_length)` assigns `10` to `integer_length`.
180+
181+
# Unit-like structs
182+
183+
You can define a struct with no members at all:
184+
185+
```rust
186+
struct Electron;
187+
```
188+
189+
Such a struct is called ‘unit-like’ because it resembles the empty
190+
tuple, `()`, sometimes called ‘unit’. Like a tuple struct, it defines a
191+
new type.
192+
193+
This is rarely useful on its own (although sometimes it can serve as a
194+
marker type), but in combination with other features, it can become
195+
useful. For instance, a library may ask you to create a structure that
196+
implements a certain [trait][trait] to handle events. If you don’t have
197+
any data you need to store in the structure, you can just create a
198+
unit-like struct.

0 commit comments

Comments
 (0)