Rust 实例 ——— 计算月天数

有没有更简单的方法??

fn main() {
    let year: u32 = 2020;
    let month: u32 = 2;
    let days: u32 = match m {
        2 if year % 4 == 0 && year % 100 != 0 || year % 400 == 0 => 29, 
        2 => 28,
        4 | 6 | 9 | 11 => 30,
        _ => 31,
    };
    
    println!("{}月{}天", month, days);
}

你可能感兴趣的:(Rust 实例 ——— 计算月天数)