summaryrefslogtreecommitdiff
path: root/solutions
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-06-08 23:42:15 +0200
committermo8it <mo8it@proton.me>2024-06-08 23:42:15 +0200
commit98db5790144a0d32009718e54051b3f7d54ae494 (patch)
tree69983a40b9b68db7c0bab34b9234aba06b28de95 /solutions
parent0338b1cbdfa567d5f9580afef1d4483c7d275c32 (diff)
primitive_types4 solution
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);
+ }
+}