[no description]
Diffstat (limited to 'build.rs')
| -rw-r--r-- | build.rs | 74 |
1 files changed, 69 insertions, 5 deletions
@@ -10,15 +10,28 @@ fn main() { File::create(Path::new(&e).join("impl_rv.rs")).unwrap(); let mut impl_pk = File::create(Path::new(&e).join("impl_pk.rs")).unwrap(); + let mut impl_rf = + File::create(Path::new(&e).join("impl_rf.rs")).unwrap(); + let mut impl_mp = + File::create(Path::new(&e).join("impl_mp.rs")).unwrap(); + for n in 0..26 { let z = ('A'..='Z').take(n).collect::<Vec<_>>().into_iter(); - generate(z, &mut impl_td, &mut impl_rv, &mut impl_pk); + generate( + z, + &mut impl_td, + &mut impl_rv, + &mut impl_pk, + &mut impl_rf, + &mut impl_mp, + ); } } -fn tup(x: impl Iterator<Item = char>) -> String { +fn tup<D: std::fmt::Display>(x: impl Iterator<Item = D>) -> String { let mut s = String::default(); for lem in x { - s.push(lem); + use std::fmt::Write; + write!(&mut s, "{lem}").unwrap(); s.push(','); } @@ -32,6 +45,8 @@ fn generate( impl_td: &mut impl Write, impl_rv: &mut impl Write, impl_pk: &mut impl Write, + impl_rf: &mut impl Write, + impl_mp: &mut impl Write, ) { let tupl = tup(x.clone()); let n = x.clone().count(); @@ -108,12 +123,61 @@ fn generate( type Reversed = ({rev}); fn reverse(self) -> Self::Reversed {{ - let ({x}) = self; + let ({tupl}) = self; ({rev}) }} }} ", - x = tup(x.clone()), + ) + .unwrap(); + write!( + impl_rf, + " + impl<{tupl}> RefIze for ({tupl}) {{ + type AsRef<'a> = ({rtup}) where + ({tupl}): 'a + ; + type AsMut<'a> = ({mtup}) where + ({tupl}): 'a + ; + fn as_ref(&self) -> Self::AsRef<'_> {{ + let ({tupl}) = self; + ({tupl}) + }} + fn as_mut(&mut self) -> Self::AsMut<'_> {{ + let ({tupl}) = self; + ({tupl}) + }} + }} + ", + rtup = tup(x.clone().map(|x| format!("&'a {x}"))), + mtup = tup(x.clone().map(|x| format!("&'a mut {x}"))), + ) + .unwrap(); + write!( + impl_mp, + // type Fns = ({fns_}); + // type Mapped = ({lowr}); + " + impl<{tupl} {ret} {fns}> MapAll<({ret}), ({fns_})> for ({tupl}) \ + {{ + fn map_all(self, ({ret}): ({fns_})) -> ({ret}) {{ + let ({tupl}) = self; + ({mapped}) + }} + }} + impl<{tupl} {ret} {fns2}> MapAllMut<({ret}), ({fns_})> for \ + ({tupl}) {{ + fn map_all_mut(self, x: &mut ({fns_})) -> ({ret}) {{ + MapAll::map_all(self, x.as_mut()) + }} + }} + ", + ret = tup(x.clone().map(|x| format!("R{x}"))), + fns_ = tup(x.clone().map(|x| format!("F{x}"))), + fns = tup(x.clone().map(|x| format!("F{x}:FnOnce({x}) -> R{x}",))), + fns2 = tup(x.clone().map(|x| format!("F{x}:FnMut({x}) -> R{x}",))), + mapped = tup(x.clone().map(|x| format!("R{}({x})", x))) ) .unwrap(); } |