From ee37f8a0065f5e050b65aadabbb66fcae5085db4 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Fri, 31 Aug 2012 11:39:05 -0700 Subject: [PATCH] Fix up the tutorial doc-tests. --- doc/tutorial.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/tutorial.md b/doc/tutorial.md index b8714bef53da..133258e17bbb 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1019,6 +1019,12 @@ To create a new record based on the value of an existing record you construct it using the `with` keyword: ~~~~ +# impl {x:float, y:float} : core::cmp::Eq { +# pure fn eq(&&other: {x:float, y:float}) -> bool { +# self.x == other.x && self.y == other.y +# } +# } + let oldpoint = {x: 10f, y: 20f}; let newpoint = {x: 0f with oldpoint}; assert newpoint == {x: 0f, y: 20f}; @@ -1437,7 +1443,10 @@ also done with square brackets (zero-based): # fn draw_scene(c: crayon) { } let crayons = ~[banana_mania, beaver, bittersweet]; -if crayons[0] == bittersweet { draw_scene(crayons[0]); } +match crayons[0] { + bittersweet => draw_scene(crayons[0]), + _ => () +} ~~~~ By default, vectors are immutable—you can not replace their elements.