ํจ์
fn gcd(a: u32, b: u32) -> u32 { if b > 0 { gcd(b, a % b) } else { a } } fn main() { println!("gcd: {}", gcd(143, 52)); }
This slide should take about 3 minutes.
- ๋งค๊ฐ๋ณ์๋ฅผ ์ ์ธํ ๋์๋ ์ด๋ฆ์ ๋จผ์ ์ฐ๊ณ , ํ์
์ ๋์ค์ ์๋๋ค. ์ด๋ฆ๊ณผ ํ์
์
:
๋ก ๊ตฌ๋ถํฉ๋๋ค. ์ด๋ ์ผ๋ถ ์ธ์ด(์๋ฅผ ๋ค์ด C)์ ๋ฐ๋์์ ์ ์ํ์๊ธฐ ๋ฐ๋๋๋ค. ๋ง์ฐฌ๊ฐ์ง๋ก, ๋ฆฌํด ํ์ ๋ ํจ์์ ์์์ด ์๋ ๊ฐ์ฅ ๋ท๋ถ๋ถ์ ์ ์ธํฉ๋๋ค. - The last expression in a function body (or any block) becomes the return value. Simply omit the
;
at the end of the expression. Thereturn
keyword can be used for early return, but the โbare valueโ form is idiomatic at the end of a function (refactorgcd
to use areturn
). - ๋ฐํ๊ฐ์ด ์๋ ํจ์์ ๊ฒฝ์ฐ, ์ ๋ ํ์
()
์ ๋ฐํํฉ๋๋ค.-> ()
๊ฐ ์๋ต๋ ๊ฒฝ์ฐ ์ปดํ์ผ๋ฌ๋ ์ด๋ฅผ ์ถ๋ก ํฉ๋๋ค. - Overloading is not supported โ each function has a single implementation.
- ํญ์ ๊ณ ์ ๋ ๊ฐ์์ ๋งค๊ฐ๋ณ์๋ฅผ ์ฌ์ฉํฉ๋๋ค. ๊ธฐ๋ณธ ์ธ์๋ ์ง์๋์ง ์์ต๋๋ค. ๋งคํฌ๋ก๋ ๊ฐ๋ณ ํจ์๋ฅผ ์ง์ํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค.
- Always takes a single set of parameter types. These types can be generic, which will be covered later.