Slices
์ฌ๋ผ์ด์ค๋ฅผ ์ฌ์ฉํ๋ฉด ํฐ ์ปฌ๋ ์ ์ ๋ถ๋ถ๋ง ํ์ธํ ์ ์์ต๋๋ค.
A slice gives you a view into a larger collection:
fn main() { let a: [i32; 6] = [10, 20, 30, 40, 50, 60]; println!("a: {a:?}"); let s: &[i32] = &a[2..4]; println!("s: {s:?}"); }
- ์ฌ๋ผ์ด์ค๋ ์ฌ๋ผ์ด์ค ํ์ ์ผ๋ก๋ถํฐ ๋ฐ์ดํฐ๋ฅผ โ๋น๋ คโ์ต๋๋ค.
- ์ง๋ฌธ:
a[3]
์ผ๋ก ์์ ํ๋ฉด ๋ฌด์จ ์ผ์ด ์์ด๋ ๊น์? - Slices borrow data from the sliced type.
- Question: What happens if you modify
a[3]
?