๋ฐฐ์—ด

fn main() {
    let mut a: [i8; 10] = [42; 10];
    a[5] = 0;
    println!("a: {a:?}");
}
This slide should take about 5 minutes.
  • A value of the array type [T; N] holds N (a compile-time constant) elements of the same type T. Note that the length of the array is part of its type, which means that [u8; 3] and [u8; 4] are considered two different types. Slices, which have a size determined at runtime, are covered later.

  • ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚œ ๋ฐฐ์—ด ์š”์†Œ์— ์•ก์„ธ์Šคํ•ด ๋ณด์„ธ์š”. ๋ฐฐ์—ด ์•ก์„ธ์Šค๋Š” ๋Ÿฐํƒ€์ž„์— ํ™•์ธ๋ฉ๋‹ˆ๋‹ค. Rust๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ์ด๋Ÿฌํ•œ ํ™•์ธ์„ ์ตœ์ ํ™”ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์•ˆ์ „ํ•˜์ง€ ์•Š์€ Rust๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฒ”์œ„ ํ™•์ธ์„ ํ•˜์ง€ ์•Š์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ๋ฆฌํ„ฐ๋Ÿด์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐฐ์—ด์— ๊ฐ’์„ ํ• ๋‹นํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • The println! macro asks for the debug implementation with the ? format parameter: {} gives the default output, {:?} gives the debug output. Types such as integers and strings implement the default output, but arrays only implement the debug output. This means that we must use debug output here.

  • #์„ ์ถ”๊ฐ€ํ•˜๋ฉด({a:#?}) ์ข€ ๋” ์ฝ๊ธฐ ์‰ฌ์šด โ€œ์ด์œโ€ ํ˜•ํƒœ๋กœ ์ถœ๋ ฅ์ด ๋ฉ๋‹ˆ๋‹ค.