Option๊ณผ Result
์ด ํ์ ์ ์ ํ์ ๋ฐ์ดํฐ๋ฅผ ๋ํ๋ ๋๋ค:
fn main() { let numbers = vec![10, 20, 30]; let first: Option<&i8> = numbers.first(); println!("first: {first:?}"); let arr: Result<[i8; 3], Vec<i8>> = numbers.try_into(); println!("arr: {arr:?}"); }
Option๊ณผResult๋ ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฟ๋ง์๋๋ผ ๋งค์ฐ ๊ด๋ฒ์ํ๊ฒ ์ฌ์ฉ๋๋ ํ์ ์ ๋๋ค.Option<&T>๋&T์ ๋นํด ๊ณต๊ฐ ์ค๋ฒํค๋๊ฐ ์์ต๋๋ค.Result๋ ์ค๋ฅ ์ฒ๋ฆฌ๋ฅผ ์ํ ํ์ค ํ์ ์ ๋๋ค. 3์ผ์ฐจ ๊ณผ์ ์์ ์ดํด๋ด ๋๋ค.try_intoattempts to convert the vector into a fixed-sized array. This can fail:- If the vector has the right size,
Result::Okis returned with the array. - Otherwise,
Result::Erris returned with the original vector.
- If the vector has the right size,