use std::env;
use std::fmt::Write;
use std::fs;
use std::path::Path;
fn main() {
let min: i32 = -20;
let max: i32 = 20;
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("const_impls.rs");
let mut out = String::new();
for a in min..=max {
let neg = -a;
if neg >= min && neg <= max {
writeln!(
&mut out,
"impl Neg for Const<{a}> {{ type Output = Const<{neg}>; fn neg(self) -> Self::Output {{ Const }} }}"
).unwrap();
}
for b in min..=max {
let sum = a + b;
if sum >= min && sum <= max {
writeln!(
&mut out,
"impl Add<Const<{b}>> for Const<{a}> {{ type Output = Const<{sum}>; fn add(self, _: Const<{b}>) -> Self::Output {{ Const }} }}"
).unwrap();
}
let diff = a - b;
if diff >= min && diff <= max {
writeln!(
&mut out,
"impl Sub<Const<{b}>> for Const<{a}> {{ type Output = Const<{diff}>; fn sub(self, _: Const<{b}>) -> Self::Output {{ Const }} }}"
).unwrap();
}
let mul = a * b;
if mul >= min && mul <= max {
writeln!(
&mut out,
"impl Mul<Const<{b}>> for Const<{a}> {{ type Output = Const<{mul}>; fn mul(self, _: Const<{b}>) -> Self::Output {{ Const }} }}"
).unwrap();
}
if b != 0 && a % b == 0 {
let div = a / b;
if div >= min && div <= max {
writeln!(
&mut out,
"impl Div<Const<{b}>> for Const<{a}> {{ type Output = Const<{div}>; fn div(self, _: Const<{b}>) -> Self::Output {{ Const }} }}"
).unwrap();
}
}
}
}
fs::write(&dest_path, out).unwrap();
println!("cargo:rerun-if-changed=build.rs");
}