ν•¨μˆ˜

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. The return keyword can be used for early return, but the β€œbare value” form is idiomatic at the end of a function (refactor gcd to use a return).
  • λ°˜ν™˜κ°’μ΄ μ—†λŠ” ν•¨μˆ˜μ˜ 경우, μœ λ‹› νƒ€μž… ()을 λ°˜ν™˜ν•©λ‹ˆλ‹€. -> ()κ°€ μƒλž΅λœ 경우 μ»΄νŒŒμΌλŸ¬λŠ” 이λ₯Ό μΆ”λ‘ ν•©λ‹ˆλ‹€.
  • 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.