Skip to content

Missing example for a value that can be present or absent in chapter 6 #2848

Closed
rust-lang/rust
#92546
@ofeks10

Description

@ofeks10
  • I have checked the latest main branch to see if this has already been fixed
  • I have searched existing issues and pull requests for duplicates

URL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html#the-option-enum-and-its-advantages-over-null-values

Description of the problem:
In my opinion, as a C developer it was hard to come up and think about examples for a value that can be present or absent.

Suggested fix:
With my friend I came up with 3 different examples I think can really give a good example for the Option enum.
The 3 are:

The C library function strstr which searches for a string inside another string - it can either find one or not (and it's not an error).
A recv from a socket which is none blocking, it may get data back or it may not.
Read an environment variable - it may have been defined or it may have not

I think the best one is the third one but I'm open to hear your opinions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions