about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGeoffrey Thomas <geofft@ldpreload.com>2015-05-12 14:13:03 -0400
committerGeoffrey Thomas <geofft@ldpreload.com>2015-05-12 20:21:19 -0400
commit457aed7ca003d7cbef2cda8360ad9b8b5bb83650 (patch)
treea9a2582f098c4c206720e42101ed2622b7631824 /src
parent2a5a320babdf000bc9cf719ccd9d95d250f83a02 (diff)
downloadrust-457aed7ca003d7cbef2cda8360ad9b8b5bb83650.tar.gz
rust-457aed7ca003d7cbef2cda8360ad9b8b5bb83650.zip
trpl: move tuple-structs.md into structs.md
Diffstat (limited to 'src')
-rw-r--r--src/doc/trpl/SUMMARY.md1
-rw-r--r--src/doc/trpl/structs.md60
-rw-r--r--src/doc/trpl/tuple-structs.md60
3 files changed, 60 insertions, 61 deletions
diff --git a/src/doc/trpl/SUMMARY.md b/src/doc/trpl/SUMMARY.md
index de7ded76280..2ab71189ff8 100644
--- a/src/doc/trpl/SUMMARY.md
+++ b/src/doc/trpl/SUMMARY.md
@@ -43,7 +43,6 @@
     * [Universal Function Call Syntax](ufcs.md)
     * [Crates and Modules](crates-and-modules.md)
     * [`const` and `static`](const-and-static.md)
-    * [Tuple Structs](tuple-structs.md)
     * [Attributes](attributes.md)
     * [`type` aliases](type-aliases.md)
     * [Casting between types](casting-between-types.md)
diff --git a/src/doc/trpl/structs.md b/src/doc/trpl/structs.md
index fcf928e427c..2f8d2bfdea0 100644
--- a/src/doc/trpl/structs.md
+++ b/src/doc/trpl/structs.md
@@ -117,3 +117,63 @@ ones, and it will copy the values you don’t specify:
 let origin = Point3d { x: 0, y: 0, z: 0 };
 let point = Point3d { z: 1, x: 2, .. origin };
 ```
+
+# Tuple structs
+
+Rust has another data type that’s like a hybrid between a [tuple][tuple] and a
+struct, called a ‘tuple struct’. Tuple structs have a name, but
+their fields don’t:
+
+```rust
+struct Color(i32, i32, i32);
+struct Point(i32, i32, i32);
+```
+
+[tuple]: primitive-types.html#tuples
+
+These two will not be equal, even if they have the same values:
+
+```rust
+# struct Color(i32, i32, i32);
+# struct Point(i32, i32, i32);
+let black = Color(0, 0, 0);
+let origin = Point(0, 0, 0);
+```
+
+It is almost always better to use a struct than a tuple struct. We would write
+`Color` and `Point` like this instead:
+
+```rust
+struct Color {
+    red: i32,
+    blue: i32,
+    green: i32,
+}
+
+struct Point {
+    x: i32,
+    y: i32,
+    z: i32,
+}
+```
+
+Now, we have actual names, rather than positions. Good names are important,
+and with a struct, we have actual names.
+
+There _is_ one case when a tuple struct is very useful, though, and that’s a
+tuple struct with only one element. We call this the ‘newtype’ pattern, because
+it allows you to create a new type, distinct from that of its contained value
+and expressing its own semantic meaning:
+
+```rust
+struct Inches(i32);
+
+let length = Inches(10);
+
+let Inches(integer_length) = length;
+println!("length is {} inches", integer_length);
+```
+
+As you can see here, you can extract the inner integer type through a
+destructuring `let`, just as with regular tuples. In this case, the
+`let Inches(integer_length)` assigns `10` to `integer_length`.
diff --git a/src/doc/trpl/tuple-structs.md b/src/doc/trpl/tuple-structs.md
deleted file mode 100644
index bdaef70711a..00000000000
--- a/src/doc/trpl/tuple-structs.md
+++ /dev/null
@@ -1,60 +0,0 @@
-% Tuple Structs
-
-Rust has another data type that's like a hybrid between a [tuple][tuple] and a
-[struct][struct], called a ‘tuple struct’. Tuple structs have a name, but
-their fields don’t:
-
-```rust
-struct Color(i32, i32, i32);
-struct Point(i32, i32, i32);
-```
-
-[tuple]: primitive-types.html#tuples
-[struct]: structs.html
-
-These two will not be equal, even if they have the same values:
-
-```rust
-# struct Color(i32, i32, i32);
-# struct Point(i32, i32, i32);
-let black = Color(0, 0, 0);
-let origin = Point(0, 0, 0);
-```
-
-It is almost always better to use a struct than a tuple struct. We would write
-`Color` and `Point` like this instead:
-
-```rust
-struct Color {
-    red: i32,
-    blue: i32,
-    green: i32,
-}
-
-struct Point {
-    x: i32,
-    y: i32,
-    z: i32,
-}
-```
-
-Now, we have actual names, rather than positions. Good names are important,
-and with a struct, we have actual names.
-
-There _is_ one case when a tuple struct is very useful, though, and that’s a
-tuple struct with only one element. We call this the ‘newtype’ pattern, because
-it allows you to create a new type, distinct from that of its contained value
-and expressing its own semantic meaning:
-
-```rust
-struct Inches(i32);
-
-let length = Inches(10);
-
-let Inches(integer_length) = length;
-println!("length is {} inches", integer_length);
-```
-
-As you can see here, you can extract the inner integer type through a
-destructuring `let`, as we discussed previously in ‘tuples’. In this case, the
-`let Inches(integer_length)` assigns `10` to `integer_length`.