2018-02-22 00:09:53 -06:00
|
|
|
// primitive_types4.rs
|
2016-02-07 11:24:38 -06:00
|
|
|
// Get a slice out of Array a where the ??? is so that the `if` statement
|
|
|
|
// returns true. Scroll down for hints!!
|
|
|
|
|
2019-08-17 19:14:00 -05:00
|
|
|
#[test]
|
2016-02-07 11:24:38 -06:00
|
|
|
fn main() {
|
|
|
|
let a = [1, 2, 3, 4, 5];
|
|
|
|
|
|
|
|
let nice_slice = ???
|
|
|
|
|
2019-08-17 19:14:00 -05:00
|
|
|
assert_eq!([2, 3, 4], nice_slice)
|
2016-02-07 11:24:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-17 19:14:00 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-07 11:24:38 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-09 13:31:14 -06:00
|
|
|
// Take a look at the Understanding Ownership -> Slices -> Other Slices section of the book:
|
2019-01-23 13:48:01 -06:00
|
|
|
// https://doc.rust-lang.org/book/ch04-03-slices.html
|
2016-02-07 11:24:38 -06:00
|
|
|
// 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
|
2018-11-09 13:31:14 -06:00
|
|
|
// reference, take a look at the Deref coercions section of the book:
|
2019-01-23 13:48:01 -06:00
|
|
|
// https://doc.rust-lang.org/book/ch15-02-deref.html
|