Module show_notes::e003
source · Expand description
No. more. nulls.
- Date: October 21, 2015
- Subject: Enumerated (
enum) types, pattern matching, and meaningful return values. - Audio
§Notes
Today’s episode discusses, in order:
- Enumerated types, with an eye to the difference between structs and
enums, and to the differences between
enums in C and in Rust. - Pattern matching, with a focus on using them with enumerated types and
some discussion about how they differ from
switchblocks in C-like languages. - Using the
OptionandResultenumerated types with pattern matching to provide meaningful returns from functions safely.
§Order
There is a specific order to the examples below, and it is not the
automatically-alphabetized order rendered by rustdoc. Instead, you should
work through in the sequence they appear in the source:
RelatedishThingsdemonstrate_basic_enumerationdemonstrate_matchget_an_optiondemonstrate_optionget_a_resultdemonstrate_result
§Links
- New Rustacean Pull Request #1
- Work on IDE support!
- Landing page
- My chosen tool: JetBrains/IntelliJ
- Rustlings
- Rust FFI Omnibus
§Follow/Support
- New Rustacean:
- Twitter: @newrustacean
- App.net: @newrustacean
- Patreon
- Email: hello@newrustacean.com
- Twitter: @newrustacean
- Chris Krycho
- Twitter: @chriskrycho
- App.net: @chriskrycho
- Twitter: @chriskrycho
Structs§
- Just exists to be used as an element in
RelatedishThings.
Enums§
- An enumeration can hold a variety of types. This one shows you a few.
Functions§
- Shows how the result of an enum comes back as increasingly complex data.
- Shows in a bit more detail how
matchworks. - Shows how an option type works in practice.
- Shows how a
Resulttype works in practice. - Shows how to return either a meaningful result or an error as an enum.
- Shows how this is used in a more meaningful context, with a standard type.
- Shows how returning a
RelatedishThings::ComplexDatainstance works. - get_name 🔒Shows how returning a
RelatedishThings::SomeNameinstance works. - Shows how returning a
RelatedishThings::ReusedStructureinstance works. - get_unit 🔒Shows how returning a
RelatedishThings::Unitinstance works. - Shows how returning a
RelatedishThings::SomeValueinstance works.