Skip to content

Commit 68c6bd7

Browse files
committed
feat: add example for slices
1 parent f72304e commit 68c6bd7

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

slices/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "slices"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]

slices/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
let a = [1, 2, 3, 4, 5];
3+
let slice = &a[1..3]; // This slice has the type &[i32]
4+
5+
// assert_eq! is a macro that panics if the two arguments aren't equal.
6+
// It's useful for testing.
7+
assert_eq!(slice, &[2, 3]);
8+
}

0 commit comments

Comments
 (0)