Skip to content

Commit 81fa634

Browse files
committed
---
yaml --- r: 210685 b: refs/heads/try c: 797d8e2 h: refs/heads/master i: 210683: 69505cc v: v3
1 parent 02c7910 commit 81fa634

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
@@ -2,7 +2,7 @@
22
refs/heads/master: 3e561f05c00cd180ec02db4ccab2840a4aba93d2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
5-
refs/heads/try: 457aed7ca003d7cbef2cda8360ad9b8b5bb83650
5+
refs/heads/try: 797d8e28695a9f349a3155958e06c527250bdac9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/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)