๋ฐฐ์ด
fn main() { let mut a: [i8; 10] = [42; 10]; a[5] = 0; println!("a: {a:?}"); }
-
A value of the array type
[T; N]
holdsN
(a compile-time constant) elements of the same typeT
. 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:#?}
) ์ข ๋ ์ฝ๊ธฐ ์ฌ์ด โ์ด์โ ํํ๋ก ์ถ๋ ฅ์ด ๋ฉ๋๋ค.