From b7dba3300e48e87e321dcfcc8db09dd3e69e48ba Mon Sep 17 00:00:00 2001 From: Adrien Tétar Date: Sun, 27 Apr 2014 11:56:29 +0900 Subject: doc: perform some 80-chars wrappings --- src/doc/tutorial.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/doc/tutorial.md') diff --git a/src/doc/tutorial.md b/src/doc/tutorial.md index 4b95cfc283f..ca636c82521 100644 --- a/src/doc/tutorial.md +++ b/src/doc/tutorial.md @@ -982,7 +982,8 @@ The obvious approach is to define `Cons` as containing an element in the list along with the next `List` node. However, this will generate a compiler error. ~~~ {.ignore} -// error: illegal recursive enum type; wrap the inner value in a box to make it representable +// error: illegal recursive enum type; wrap the inner value in a box to make it +// representable enum List { Cons(u32, List), // an element (`u32`) and the next node in the list Nil @@ -1054,10 +1055,10 @@ immutable, the whole list is immutable. The memory allocation itself is the box, while the owner holds onto a pointer to it: ~~~ {.notrust} - List box List box List box List box - +--------------+ +--------------+ +--------------+ +--------------+ -list -> | Cons | 1 | ~ | -> | Cons | 2 | ~ | -> | Cons | 3 | ~ | -> | Nil | - +--------------+ +--------------+ +--------------+ +--------------+ + List box List box List box List box + +--------------+ +--------------+ +--------------+ +----------+ +list -> | Cons | 1 | ~ | -> | Cons | 2 | ~ | -> | Cons | 3 | ~ | -> | Nil | + +--------------+ +--------------+ +--------------+ +----------+ ~~~ > *Note:* the above diagram shows the logical contents of the enum. The actual @@ -1197,7 +1198,8 @@ fn eq(xs: &List, ys: &List) -> bool { // If we have reached the end of both lists, they are equal. (&Nil, &Nil) => true, // If the current element in both lists is equal, keep going. - (&Cons(x, ~ref next_xs), &Cons(y, ~ref next_ys)) if x == y => eq(next_xs, next_ys), + (&Cons(x, ~ref next_xs), &Cons(y, ~ref next_ys)) + if x == y => eq(next_xs, next_ys), // If the current elements are not equal, the lists are not equal. _ => false } @@ -1256,7 +1258,7 @@ Using the generic `List` works much like before, thanks to type inference: # Cons(value, ~xs) # } let mut xs = Nil; // Unknown type! This is a `List`, but `T` can be anything. -xs = prepend(xs, 10); // The compiler infers the type of `xs` as `List` from this. +xs = prepend(xs, 10); // Here the compiler infers `xs`'s type as `List`. xs = prepend(xs, 15); xs = prepend(xs, 20); ~~~ @@ -1303,7 +1305,8 @@ fn eq(xs: &List, ys: &List) -> bool { // If we have reached the end of both lists, they are equal. (&Nil, &Nil) => true, // If the current element in both lists is equal, keep going. - (&Cons(ref x, ~ref next_xs), &Cons(ref y, ~ref next_ys)) if x == y => eq(next_xs, next_ys), + (&Cons(ref x, ~ref next_xs), &Cons(ref y, ~ref next_ys)) + if x == y => eq(next_xs, next_ys), // If the current elements are not equal, the lists are not equal. _ => false } @@ -1331,7 +1334,8 @@ impl Eq for List { // If we have reached the end of both lists, they are equal. (&Nil, &Nil) => true, // If the current element in both lists is equal, keep going. - (&Cons(ref x, ~ref next_xs), &Cons(ref y, ~ref next_ys)) if x == y => next_xs == next_ys, + (&Cons(ref x, ~ref next_xs), &Cons(ref y, ~ref next_ys)) + if x == y => next_xs == next_ys, // If the current elements are not equal, the lists are not equal. _ => false } -- cgit 1.4.1-3-g733a5