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

Rename Option in tutorial to workaround iteration bug. #15707

Closed
wants to merge 5 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2079,21 +2079,23 @@ struct Stack<T> {
elements: Vec<T>
}

enum Option<T> {
Some(T),
None
enum Maybe<T> {
Just(T),
Nothing
}
# fn main() {}
~~~~

These declarations can be instantiated to valid types like `Set<int>`,
`Stack<int>`, and `Option<int>`.

The last type in that example, `Option`, appears frequently in Rust code.
Because Rust does not have null pointers (except in unsafe code), we need
another way to write a function whose result isn't defined on every possible
combination of arguments of the appropriate types. The usual way is to write
a function that returns `Option<T>` instead of `T`.
`Stack<int>`, and `Maybe<int>`.

The last type in that example, `Maybe`, is already defined in Rust as
the type `Option` with the constants `Some(T)` and `None`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, maybe it should not be 'constants', but 'variants'

`Option` appears frequently in Rust code.
Because Rust does not have null pointers (except in unsafe code),
we need another way to write a function whose result isn't defined on every
possible combination of arguments of the appropriate types. The usual way is to
write a function that returns `Option<T>` instead of `T`.

~~~~
# struct Point { x: f64, y: f64 }
Expand Down