From 7e49659102f0977d9142190e1ba23345c0f00eb1 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 3 Aug 2021 21:41:35 -0400 Subject: [PATCH] Make explicit that enum variant construction is a function Connects to #800. --- src/ch06-01-defining-an-enum.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ch06-01-defining-an-enum.md b/src/ch06-01-defining-an-enum.md index 4502c35693..ce581642f0 100644 --- a/src/ch06-01-defining-an-enum.md +++ b/src/ch06-01-defining-an-enum.md @@ -79,7 +79,12 @@ variants will have associated `String` values: ``` We attach data to each variant of the enum directly, so there is no need for an -extra struct. +extra struct. Here it’s also easier to see another detail of how enums work: +the name of each enum variant that we define also becomes a function that +constructs an instance of the enum. That is, `IpAddr::V4()` is a function call +that takes a `String` argument and returns an instance of the `IpAddr` type. We +automatically get this constructor function defined as a result of defining the +enum. There’s another advantage to using an enum rather than a struct: each variant can have different types and amounts of associated data. Version four type IP