use std::{env, fmt, fs, path};
use std::io::Write;
fn main() {
let mut running_sum_common = 0;
let mut running_sum_leap = 0;
let month_data = [
("January", 31, 31),
("February", 28, 29),
("March", 31, 31),
("April", 30, 30),
("May", 31, 31),
("June", 30, 30),
("July", 31, 31),
("August", 31, 31),
("September", 30, 30),
("October", 31, 31),
("November", 30, 30),
("December", 31, 31),
].iter().enumerate().map(|(i, &(name, length_common, length_leap))| {
running_sum_common += length_common;
running_sum_leap += length_leap;
(
Ident(name),
i + 1, length_common,
length_leap,
running_sum_common - length_common,
running_sum_common - 1,
running_sum_leap - length_leap,
running_sum_leap - 1,
)
}).collect::<Vec<_>>();
let day_of_the_week_data = [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
].iter().enumerate().map(|(i, &name)| (Ident(name), i + 1)).collect::<Vec<_>>();
let path = path::Path::new(&env::var("OUT_DIR").unwrap()).join("generated_data.rs");
let mut file = fs::File::create(&path).unwrap();
macro_rules! with {
($variable: ident) => {
writeln!(
file,
"macro_rules! with_{} {{ ($macro_name: ident) => {{ $macro_name!({:?}); }} }}",
stringify!($variable),
$variable
).unwrap()
}
}
with!(month_data);
with!(day_of_the_week_data);
}
struct Ident(&'static str);
impl fmt::Debug for Ident {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}