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 ๋ฑ)์ ์ด๋ฅผ ํ๊ธฐํ๊ธฐ ์ํด ๋จ์ผ ๊ฐ์ ๋ํํ๋ ํจํด์ ๋๋ค.(์์๋ ๋ฌผ๋ฆฌ ๋จ์(๋ดํด, ํ์ด๋(ํ))๋ฅผ ๋ํํ๊ณ ์์ต๋๋ค. )