
23
1
장
타입
pub enum Sides {
Both,
Single,
}
pub enum Output {
BlackAndWhite,
Color,
}
pub fn print_page(sides: Sides, color: Output) {
// ...
}
그러면 다음과 같이 호출 지점의 가독성과 타입 안전성을 높일 수 있다.
print_page(Sides::Both, Output::BlackAndWhite);
bool
타입 인수를 받도록 정의할 때와 달리, 라이브러리 사용자가 실수로 인수의 순서를 바꿔
적으면 컴파일러가 즉시 오류 메시지를 출력한다.
error[E0308]: arguments to this function are incorrect
--> src/main.rs:104:9
|
104 | print_page(Output::BlackAndWhite, Sides::Single);
| ^^^^^^^^^^ --------------------- ------------- expected `enums::Output`,
| | found `enums::Sides`
| |
| expected `enums::Sides`, found `enums::Output`
|
note: function defined here
--> src/main.rs:145:12
|
145 | pub ...