Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Unit-like Struct declaration/usage example #2442

Closed
ChrisKeefe opened this issue Aug 27, 2020 · 1 comment · Fixed by rust-lang/rust#87925
Closed

ENH: Unit-like Struct declaration/usage example #2442

ChrisKeefe opened this issue Aug 27, 2020 · 1 comment · Fixed by rust-lang/rust#87925
Milestone

Comments

@ChrisKeefe
Copy link

Hi folks! I've been having a great time self-teaching with The Book and Rustlings, but ran into a little speed bump in chapter 5-1.

The Issue

There is a section describing unit-like structs in the book, but no example of how to declare or instantiate them.

The worked example from the first edition appears to have been removed. Declaring a unit-like struct is visible in the structs1 rustling, but it's not completely clear from that example what the syntax is doing - for example, is UnitStruct is a user-defined name, or something defined in the prelude? Instantiating a unit-like struct does not seem to be shown in the Book or in Rustlings. Appendix B is amazing if you know what you're looking for, but not super helpful here.

Proposed solution

Re-introduce the worked example from edition 1, or re-introduce a simplified example with the preferred syntax:

// Instantiate a unit-like struct with a name and a semi-colon.
struct Proton;

// Use the same notation when creating an instance.
let y = Proton;

NOTE: I have no idea which syntax is more idiomatic! 😂

If this is something the maintainers/community are interested in, I'd be happy to knock together a PR. Thanks again for making Rust so accessible!

@Degerada
Copy link

Please do, I came across the same issue when doing exercises with rustling!

@carols10cents carols10cents added this to the ch5 milestone Jul 14, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Aug 11, 2021
Update books

## nomicon

2 commits in f51734eb5566c826b471977747ea3d7d6915bbe9..0c7e5bd1428e7838252bb57b7f0fbfda4ec82f02
2021-07-23 18:24:35 +0900 to 2021-08-04 10:18:22 -0700
- Document lifetime elision for fn types, Fn*, impl (rust-lang/nomicon#298)
- Remove unnecessary `extern crate`s (rust-lang/nomicon#297)

## reference

3 commits in 3b7be075af5d6e402a18efff672a8a265b4596fd..4884fe45c14f8b22121760fb117181bb4da8dfe0
2021-07-26 13:20:11 -0700 to 2021-07-28 21:31:28 -0700
- Mention "function item type to `fn pointer`" coercion (rust-lang/reference#1079)
- example for bindings after at (rust-lang/reference#1027)
- array-expr.md: fix typo; 'polish' sentence (rust-lang/reference#1080)

## book

10 commits in a07036f864b37896b31eb996cd7aedb489f69a1f..7e49659102f0977d9142190e1ba23345c0f00eb1
2021-07-26 20:19:46 -0400 to 2021-08-03 21:41:35 -0400
- Make explicit that enum variant construction is a function
- Clarify why None means we have to annotate the type
- Make the convert quotes script able to do one chapter
- Snapshot of chapter 5
-  (rust-lang/book#2811)
-  (rust-lang/book#2809)
- Ugh quote script, that's not right
- Introduce the dbg macro. Connects to rust-lang/book#1658
- Add an example of declaring and instantiating unit-like structs. Fixes rust-lang/book#2442.
- Remove authors field from all the manifests (rust-lang/book#2805)

## rustc-dev-guide

5 commits in 09343d6f921d2a07c66f8c41ec3d65bf1fa52556..c4644b427cbdaafc7a87be0ccdf5d8aaa07ac35f
2021-07-26 00:37:28 +0200 to 2021-08-10 20:41:44 +0900
- Remove a dead link in `new-target.md` + other nits (rust-lang/rustc-dev-guide#1186)
- Add description of -opt-bisect-limit LLVM option (rust-lang/rustc-dev-guide#1182)
- Fixed team responsible for stabilization (rust-lang/rustc-dev-guide#1181)
- Add S-Inactive PRs as another source of things contributors could work on (rust-lang/rustc-dev-guide#1177)
- git.md: Fix No-Merge Policy link

## embedded-book

1 commits in 09986cd352404eb4659db44613b27cac9aa652fc..4f9fcaa30d11ba52b641e6fd5206536d65838af9
2021-07-18 19:26:46 +0000 to 2021-08-06 17:43:12 +0000
- Fix typo in 'Memory Mapped Registers'  (rust-embedded/book#298)
JohnTitor added a commit to JohnTitor/rust that referenced this issue Aug 11, 2021
Update books

## nomicon

2 commits in f51734eb5566c826b471977747ea3d7d6915bbe9..0c7e5bd1428e7838252bb57b7f0fbfda4ec82f02
2021-07-23 18:24:35 +0900 to 2021-08-04 10:18:22 -0700
- Document lifetime elision for fn types, Fn*, impl (rust-lang/nomicon#298)
- Remove unnecessary `extern crate`s (rust-lang/nomicon#297)

## reference

3 commits in 3b7be075af5d6e402a18efff672a8a265b4596fd..4884fe45c14f8b22121760fb117181bb4da8dfe0
2021-07-26 13:20:11 -0700 to 2021-07-28 21:31:28 -0700
- Mention "function item type to `fn pointer`" coercion (rust-lang/reference#1079)
- example for bindings after at (rust-lang/reference#1027)
- array-expr.md: fix typo; 'polish' sentence (rust-lang/reference#1080)

## book

10 commits in a07036f864b37896b31eb996cd7aedb489f69a1f..7e49659102f0977d9142190e1ba23345c0f00eb1
2021-07-26 20:19:46 -0400 to 2021-08-03 21:41:35 -0400
- Make explicit that enum variant construction is a function
- Clarify why None means we have to annotate the type
- Make the convert quotes script able to do one chapter
- Snapshot of chapter 5
-  (rust-lang/book#2811)
-  (rust-lang/book#2809)
- Ugh quote script, that's not right
- Introduce the dbg macro. Connects to rust-lang/book#1658
- Add an example of declaring and instantiating unit-like structs. Fixes rust-lang/book#2442.
- Remove authors field from all the manifests (rust-lang/book#2805)

## rustc-dev-guide

5 commits in 09343d6f921d2a07c66f8c41ec3d65bf1fa52556..c4644b427cbdaafc7a87be0ccdf5d8aaa07ac35f
2021-07-26 00:37:28 +0200 to 2021-08-10 20:41:44 +0900
- Remove a dead link in `new-target.md` + other nits (rust-lang/rustc-dev-guide#1186)
- Add description of -opt-bisect-limit LLVM option (rust-lang/rustc-dev-guide#1182)
- Fixed team responsible for stabilization (rust-lang/rustc-dev-guide#1181)
- Add S-Inactive PRs as another source of things contributors could work on (rust-lang/rustc-dev-guide#1177)
- git.md: Fix No-Merge Policy link

## embedded-book

1 commits in 09986cd352404eb4659db44613b27cac9aa652fc..4f9fcaa30d11ba52b641e6fd5206536d65838af9
2021-07-18 19:26:46 +0000 to 2021-08-06 17:43:12 +0000
- Fix typo in 'Memory Mapped Registers'  (rust-embedded/book#298)
JohnTitor added a commit to JohnTitor/rust that referenced this issue Aug 12, 2021
Update books

## nomicon

2 commits in f51734eb5566c826b471977747ea3d7d6915bbe9..0c7e5bd1428e7838252bb57b7f0fbfda4ec82f02
2021-07-23 18:24:35 +0900 to 2021-08-04 10:18:22 -0700
- Document lifetime elision for fn types, Fn*, impl (rust-lang/nomicon#298)
- Remove unnecessary `extern crate`s (rust-lang/nomicon#297)

## reference

3 commits in 3b7be075af5d6e402a18efff672a8a265b4596fd..4884fe45c14f8b22121760fb117181bb4da8dfe0
2021-07-26 13:20:11 -0700 to 2021-07-28 21:31:28 -0700
- Mention "function item type to `fn pointer`" coercion (rust-lang/reference#1079)
- example for bindings after at (rust-lang/reference#1027)
- array-expr.md: fix typo; 'polish' sentence (rust-lang/reference#1080)

## book

10 commits in a07036f864b37896b31eb996cd7aedb489f69a1f..7e49659102f0977d9142190e1ba23345c0f00eb1
2021-07-26 20:19:46 -0400 to 2021-08-03 21:41:35 -0400
- Make explicit that enum variant construction is a function
- Clarify why None means we have to annotate the type
- Make the convert quotes script able to do one chapter
- Snapshot of chapter 5
-  (rust-lang/book#2811)
-  (rust-lang/book#2809)
- Ugh quote script, that's not right
- Introduce the dbg macro. Connects to rust-lang/book#1658
- Add an example of declaring and instantiating unit-like structs. Fixes rust-lang/book#2442.
- Remove authors field from all the manifests (rust-lang/book#2805)

## rustc-dev-guide

5 commits in 09343d6f921d2a07c66f8c41ec3d65bf1fa52556..c4644b427cbdaafc7a87be0ccdf5d8aaa07ac35f
2021-07-26 00:37:28 +0200 to 2021-08-10 20:41:44 +0900
- Remove a dead link in `new-target.md` + other nits (rust-lang/rustc-dev-guide#1186)
- Add description of -opt-bisect-limit LLVM option (rust-lang/rustc-dev-guide#1182)
- Fixed team responsible for stabilization (rust-lang/rustc-dev-guide#1181)
- Add S-Inactive PRs as another source of things contributors could work on (rust-lang/rustc-dev-guide#1177)
- git.md: Fix No-Merge Policy link

## embedded-book

1 commits in 09986cd352404eb4659db44613b27cac9aa652fc..4f9fcaa30d11ba52b641e6fd5206536d65838af9
2021-07-18 19:26:46 +0000 to 2021-08-06 17:43:12 +0000
- Fix typo in 'Memory Mapped Registers'  (rust-embedded/book#298)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants