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

Write documentation for the Termination trait #740

Closed
Closed
Changes from all 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
Write documentation for the Termination trait
  • Loading branch information
LeSeulArtichaut committed Jan 25, 2020
commit a8c2109690cc59f2f2c98a2bd0970478538e2401
25 changes: 25 additions & 0 deletions src/special-types-and-traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,37 @@ compile-time; that is, it's not a [dynamically sized type]. [Type parameters]
are `Sized` by default. `Sized` is always implemented automatically by the
compiler, not by [implementation items].

## `Termination`

Types implementing the [`Termination`] trait can be returned from `main()`.
Those types implement logic to be converted to an integer value returned
to the operating system when the program ends.

The standard library has implementations for the following types:

* [`ExitCode`] represents conventional return values, depending on the
operating system. This includes `SUCCESS` and `FAILURE` variants, but
could be extanded in the future.
* `()` returns `ExitCode::SUCCESS`
* `Result<(), E>` returns `ExitCode::SUCCESS` for an `Ok` variant,
and prints an error before exiting with `ExitCode::FAILURE` for an
`Err` variant.
* [`!`] cannot be constructed, thus can never be returned. Using this as a
return type for `main()` denotes that the program will run forever, unless
it is interrupted by the operating system.
* `Result<!, E>` prints the `Err` and exits with `ExitCode::FAILURE` when
returned, since the `Ok` variant containts [`!`] cannot be constructed.
Using this as return type for `main()` denotes that the program will run forever,
unless it is interrupted or it encounters an error

[`Arc<Self>`]: ../std/sync/struct.Arc.html
[`Box<T>`]: ../std/boxed/struct.Box.html
[`Clone`]: ../std/clone/trait.Clone.html
[`Copy`]: ../std/marker/trait.Copy.html
[`Deref`]: ../std/ops/trait.Deref.html
[`DerefMut`]: ../std/ops/trait.DerefMut.html
[`Drop`]: ../std/ops/trait.Drop.html
[`ExitCode`]: ../std/process/struct.ExitCode.html
[`Pin<P>`]: ../std/pin/struct.Pin.html
[`Rc<Self>`]: ../std/rc/struct.Rc.html
[`RefUnwindSafe`]: ../std/panic/trait.RefUnwindSafe.html
Expand All @@ -157,6 +181,7 @@ compiler, not by [implementation items].
[`std::ops`]: ../std/ops/index.html
[`UnwindSafe`]: ../std/panic/trait.UnwindSafe.html
[`Sync`]: ../std/marker/trait.Sync.html
[`Termination`]: ../std/process/trait.Termination.html

[Arrays]: types/array.md
[call expressions]: expressions/call-expr.md
Expand Down