Hi, I started working on a datetime module that you can check out at:
https://github.com/tedhorst/rust_datetime While working on this I had some questions about rust style or idioms. The first one was about how to implement what would be static arrays in C, e.g.: static int MONTHLENGTH[][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}}; Rust doesn't support const vectors, so I ended up having to do this in a function using alts: fn month_length(m: u8, ly: bool) -> u8 { alt ly { true { alt check m { 1_u8 { 31_u8 } 2_u8 { 29_u8 } 3_u8 { 31_u8 } 4_u8 { 30_u8 } 5_u8 { 31_u8 } 6_u8 { 30_u8 } 7_u8 { 31_u8 } 8_u8 { 31_u8 } 9_u8 { 30_u8 } 10_u8 { 31_u8 } 11_u8 { 30_u8 } 12_u8 { 31_u8 } } } false { alt check m { 1_u8 { 31_u8 } 2_u8 { 28_u8 } 3_u8 { 31_u8 } 4_u8 { 30_u8 } 5_u8 { 31_u8 } 6_u8 { 30_u8 } 7_u8 { 31_u8 } 8_u8 { 31_u8 } 9_u8 { 30_u8 } 10_u8 { 31_u8 } 11_u8 { 30_u8 } 12_u8 { 31_u8 } } } } } Is there a better way to do this in rust? Ted _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
