Skip to content

Commit 0864885

Browse files
committed
doc: Remove documentation on newtype enums.
1 parent 7c04000 commit 0864885

File tree

1 file changed

+36
-44
lines changed

1 file changed

+36
-44
lines changed

doc/tutorial.md

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -681,45 +681,6 @@ the value of `North` is 0, `East` is 1, `South` is 2, and `West` is 3.
681681
When an enum is C-like, you can apply the `as` cast operator to
682682
convert it to its discriminator value as an `int`.
683683

684-
<a name="single_variant_enum"></a>
685-
686-
There is a special case for enums with a single variant, which are
687-
sometimes called "newtype-style enums" (after Haskell's "newtype"
688-
feature). These are used to define new types in such a way that the
689-
new name is not just a synonym for an existing type, but its own
690-
distinct type: `type` creates a structural synonym, while this form of
691-
`enum` creates a nominal synonym. If you say:
692-
693-
~~~~
694-
enum GizmoId = int;
695-
~~~~
696-
697-
That is a shorthand for this:
698-
699-
~~~~
700-
enum GizmoId { GizmoId(int) }
701-
~~~~
702-
703-
You can extract the contents of such an enum type with the
704-
dereference (`*`) unary operator:
705-
706-
~~~~
707-
# enum GizmoId = int;
708-
let my_gizmo_id: GizmoId = GizmoId(10);
709-
let id_int: int = *my_gizmo_id;
710-
~~~~
711-
712-
Types like this can be useful to differentiate between data that have
713-
the same type but must be used in different ways.
714-
715-
~~~~
716-
enum Inches = int;
717-
enum Centimeters = int;
718-
~~~~
719-
720-
The above definitions allow for a simple way for programs to avoid
721-
confusing numbers that correspond to different units.
722-
723684
For enum types with multiple variants, destructuring is the only way to
724685
get at their contents. All variant constructors can be used as
725686
patterns, as in this definition of `area`:
@@ -789,10 +750,10 @@ match mytup {
789750

790751
## Tuple structs
791752

792-
Rust also has _nominal tuples_, which behave like both structs and tuples,
793-
except that nominal tuple types have names
794-
(so `Foo(1, 2)` has a different type from `Bar(1, 2)`),
795-
and nominal tuple types' _fields_ do not have names.
753+
Rust also has _tuple structs_, which behave like both structs and tuples,
754+
except that, unlike tuples, tuple structs have names (so `Foo(1, 2)` has a
755+
different type from `Bar(1, 2)`), and tuple structs' _fields_ do not have
756+
names.
796757

797758
For example:
798759
~~~~
@@ -803,6 +764,37 @@ match mytup {
803764
}
804765
~~~~
805766

767+
<a name="newtype"></a>
768+
769+
There is a special case for tuple structs with a single field, which are
770+
sometimes called "newtypes" (after Haskell's "newtype" feature). These are
771+
used to define new types in such a way that the new name is not just a
772+
synonym for an existing type but is rather its own distinct type.
773+
774+
~~~~
775+
struct GizmoId(int);
776+
~~~~
777+
778+
For convenience, you can extract the contents of such a struct with the
779+
dereference (`*`) unary operator:
780+
781+
~~~~
782+
# struct GizmoId(int);
783+
let my_gizmo_id: GizmoId = GizmoId(10);
784+
let id_int: int = *my_gizmo_id;
785+
~~~~
786+
787+
Types like this can be useful to differentiate between data that have
788+
the same type but must be used in different ways.
789+
790+
~~~~
791+
struct Inches(int);
792+
struct Centimeters(int);
793+
~~~~
794+
795+
The above definitions allow for a simple way for programs to avoid
796+
confusing numbers that correspond to different units.
797+
806798
# Functions
807799

808800
We've already seen several function definitions. Like all other static
@@ -2294,7 +2286,7 @@ struct level. Note that fields and methods are _public_ by default.
22942286
pub mod farm {
22952287
# pub type Chicken = int;
22962288
# type Cow = int;
2297-
# enum Human = int;
2289+
# struct Human(int);
22982290
# impl Human { fn rest(&self) { } }
22992291
# pub fn make_me_a_farm() -> Farm { Farm { chickens: ~[], cows: ~[], farmer: Human(0) } }
23002292
pub struct Farm {

0 commit comments

Comments
 (0)