在这种情况下,“类型归因”指的是什么?

时间:2019-03-26 01:28:16

标签: enums rust match println arity

在这种情况下,错误归因指的是什么?如何根据传入的Arity将代码固定到println?

运行下面的代码将引发错误:

error: expected type, found `10`
  --> src/main.rs:21:27
   |
21 |    tellTime(Clock:Sundial(10));
   |                           ^^ expecting a type here because of type ascription

main.rs:

enum Clock {
    Sundial(u8),
    Digital(u8, u8),
    Analog(u8, u8, u8),
}

fn tellTime(clock: Clock) {
    match clock {
      Clock::Sundial(hours) =>
          println!("Time is: {}", hours),
      Clock::Digital(hours, mins) =>
          println!("Time is: {}:{}", hours, mins),
      Clock::Analog(hours, mins, secs) =>
          println!("Time is: {}:{}:{}", hours, mins, secs),
      _ => println!("Not a clock!")

    }

}
fn main() {
   tellTime(Clock:Sundial(10));
}

0 个答案:

没有答案