From 98cde6f9b1f89cea2726537ee901b422a780ff12 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Sun, 7 Feb 2016 12:24:38 -0500 Subject: [PATCH] =?UTF-8?q?Add=20slice=20exercise=20from=20@ruipserra!!!?= =?UTF-8?q?=20=F0=9F=92=AB=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Connects to #29 --- primitive_types/primitive_types4.rs | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 primitive_types/primitive_types4.rs diff --git a/primitive_types/primitive_types4.rs b/primitive_types/primitive_types4.rs new file mode 100644 index 0000000..b71cc33 --- /dev/null +++ b/primitive_types/primitive_types4.rs @@ -0,0 +1,48 @@ +// Get a slice out of Array a where the ??? is so that the `if` statement +// returns true. Scroll down for hints!! + +fn main() { + let a = [1, 2, 3, 4, 5]; + + let nice_slice = ??? + + if nice_slice == [2, 3, 4] { + println!("Nice slice!"); + } else { + println!("Not quite what I was expecting... I see: {:?}", nice_slice); + } +} + + + + + + + + + + + + + + + + + + + + + + + + + +// Take a look at the Primitive Types -> Slices section of the book: +// http://doc.rust-lang.org/stable/book/primitive-types.html#slices +// and use the starting and ending indices of the items in the Array +// that you want to end up in the slice. + +// If you're curious why the right hand of the `==` comparison does not +// have an ampersand for a reference since the left hand side is a +// reference, take a look at the Deref coercions chapter: +// http://doc.rust-lang.org/stable/book/deref-coercions.html