ν¨μ
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.