mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-04 17:23:36 +02:00
primitive_types4 solution
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user