summaryrefslogtreecommitdiff
path: root/solutions
diff options
context:
space:
mode:
Diffstat (limited to 'solutions')
-rw-r--r--solutions/04_primitive_types/primitive_types4.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/solutions/04_primitive_types/primitive_types4.rs b/solutions/04_primitive_types/primitive_types4.rs
index 4e18198..4807e66 100644
--- a/solutions/04_primitive_types/primitive_types4.rs
+++ b/solutions/04_primitive_types/primitive_types4.rs
@@ -1 +1,23 @@
-// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
+fn main() {
+ // You can optionally experiment here.
+}
+
+#[cfg(test)]
+mod tests {
+ #[test]
+ fn slice_out_of_array() {
+ let a = [1, 2, 3, 4, 5];
+ // 0 1 2 3 4 <- indices
+ // -------
+ // |
+ // +--- slice
+
+ // Note that the upper index 4 is excluded.
+ let nice_slice = &a[1..4];
+ assert_eq!([2, 3, 4], nice_slice);
+
+ // The upper index can be included by using the syntax `..=` (with `=` sign)
+ let nice_slice = &a[1..=3];
+ assert_eq!([2, 3, 4], nice_slice);
+ }
+}