Tuple Structs

๊ฐ ๊ฐ’์˜ ์ด๋ฆ„์ด ์ค‘์š”ํ•˜์ง€ ์•Š๋‹ค๋ฉด ํŠœ๋ธ” ๊ตฌ์กฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

If the field names are unimportant, you can use a tuple struct:

struct Point(i32, i32);

fn main() {
    let p = Point(17, 23);
    println!("({}, {})", p.0, p.1);
}

์ข…์ข… ๋‹จ์ผ ํ•„๋“œ์˜ ๋ž˜ํผ(wrapper)๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.(๋Ÿฌ์ŠคํŠธ์—์„œ newtypes ํŒจํ„ด1์ด๋ผ ๋ถ€๋ฆ…๋‹ˆ๋‹ค):

This is often used for single-field wrappers (called newtypes):

struct PoundOfForce(f64);
struct Newtons(f64);

fn compute_thruster_force() -> PoundOfForce {
    todo!("Ask a rocket scientist at NASA")
}

fn set_thruster_force(force: Newtons) {
    // ...
}

fn main() {
    let force = compute_thruster_force();
    set_thruster_force(force);
}

์—ญ์ฃผ

1

๊ฐ’ ์ž์ฒด๊ฐ€ ์˜๋ฏธ๋ฅผ ๊ฐ€์ง€๋Š” ๊ฒฝ์šฐ(cm, mm, kg ๋“ฑ)์— ์ด๋ฅผ ํ‘œ๊ธฐํ•˜๊ธฐ ์œ„ํ•ด ๋‹จ์ผ ๊ฐ’์„ ๋ž˜ํ•‘ํ•˜๋Š” ํŒจํ„ด์ž…๋‹ˆ๋‹ค.(์˜ˆ์‹œ๋Š” ๋ฌผ๋ฆฌ ๋‹จ์œ„(๋‰ดํ„ด, ํŒŒ์šด๋“œ(ํž˜))๋ฅผ ๋ž˜ํ•‘ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. )