[no description]
use decl macro more
| -rw-r--r-- | build.rs | 28 | ||||
| -rw-r--r-- | src/implementations.rs | 42 | ||||
| -rw-r--r-- | src/iterator.rs | 19 | ||||
| -rw-r--r-- | src/lib.rs | 21 |
4 files changed, 59 insertions, 51 deletions
@@ -10,8 +10,6 @@ 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(); @@ -22,7 +20,6 @@ fn main() { &mut impl_td, &mut impl_rv, &mut impl_pk, - &mut impl_rf, &mut impl_mp, ); } @@ -45,7 +42,6 @@ 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()); @@ -131,30 +127,6 @@ fn generate( ) .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}); diff --git a/src/implementations.rs b/src/implementations.rs index a2ae4fe..22b88c5 100644 --- a/src/implementations.rs +++ b/src/implementations.rs @@ -42,6 +42,18 @@ impl Tupl for () { fn snoc(_: Self::Init, last: Self::Last) -> Self { match last {} } + + type AsRef<'a> = (); + + fn as_ref(&self) -> Self::AsRef<'_> { + () + } + + type AsMut<'a> = (); + + fn as_mut(&mut self) -> Self::AsMut<'_> { + () + } } impl<T> Tupl for (T,) { const LEN: usize = 1; @@ -68,6 +80,26 @@ impl<T> Tupl for (T,) { fn fcons(_: Self::Head, _: Self::Inner, _: Self::Last) -> Self { unimplemented!("dont call base case.") } + + type AsRef<'a> + = (&'a T,) + where + Self: 'a; + + fn as_ref(&self) -> Self::AsRef<'_> { + let (x,) = self; + (x,) + } + + type AsMut<'a> + = (&'a mut T,) + where + Self: 'a; + + fn as_mut(&mut self) -> Self::AsMut<'_> { + let (x,) = self; + (x,) + } } macro_rules! do_impl { @@ -109,6 +141,16 @@ macro_rules! do_impl { let ($hd, $($i,)* $tl) = self; (($hd, $($i,)*), $tl) } + type AsRef<'a> = (&'a $hd, $(&'a $i,)* &'a $tl,) where Self:'a; + fn as_ref<'a>(&'a self) -> Self::AsRef<'a> { + let ($hd, $($i,)* $tl) = self; + ($hd, $($i,)* $tl) + } + type AsMut<'a> = (&'a mut $hd, $(&'a mut $i,)* &'a mut $tl,) where Self:'a; + fn as_mut<'a>(&'a mut self) -> Self::AsMut<'a> { + let ($hd, $($i,)* $tl) = self; + ($hd, $($i,)* $tl) + } // fn array(self) -> [T; 0 $(+ { stringify!($i); 1 } )*] { // with_vars! { // [acc: ] diff --git a/src/iterator.rs b/src/iterator.rs index c32c516..a38e8db 100644 --- a/src/iterator.rs +++ b/src/iterator.rs @@ -1,5 +1,5 @@ #![allow(nonstandard_style)] -use crate::{MapAllMut, Pick, RePick, RefIze, Tupl}; +use crate::{MapAllMut, Pick, RePick, Tupl}; pub trait IteratorOfTuplesWithF<retval>: Iterator<Item: Tupl> + Sized { @@ -74,11 +74,8 @@ pub trait IteratorOfTuplesWithF<retval>: self.on().flat_map(f) } } -pub trait IteratorOfReferencesToTupleWithF< - 'a, - T: Tupl + RefIze + 'a, - retval, ->: Iterator<Item = &'a T> + Sized +pub trait IteratorOfReferencesToTupleWithF<'a, T: Tupl + 'a, retval>: + Iterator<Item = &'a T> + Sized { /// Map the item at: (|(x, y)| (f(x), y)) fn map_at<const N: usize>( @@ -149,12 +146,10 @@ pub trait IteratorOfTuples: Iterator<Item: Tupl> + Sized { } /// may add more later -pub trait IteratorOfReferencesToTuple<'a, T: Tupl + RefIze + 'a>: +pub trait IteratorOfReferencesToTuple<'a, T: Tupl + 'a>: Iterator<Item = &'a T> + Sized { - fn as_ref( - self, - ) -> core::iter::Map<Self, fn(&T) -> <T as RefIze>::AsRef<'_>> { + fn as_ref(self) -> core::iter::Map<Self, fn(&T) -> <T>::AsRef<'_>> { self.map(T::as_ref) } @@ -182,12 +177,12 @@ impl<I: Iterator<Item: Tupl>> IteratorOfTuples for I {} impl<U, I: Iterator<Item: Tupl>> IteratorOfTuplesWithF<U> for I {} -impl<'a, T: Tupl + RefIze + 'a, I: Iterator<Item = &'a T>> +impl<'a, T: Tupl + 'a, I: Iterator<Item = &'a T>> IteratorOfReferencesToTuple<'a, T> for I { } -impl<'a, U, T: Tupl + RefIze + 'a, I: Iterator<Item = &'a T>> +impl<'a, U, T: Tupl + 'a, I: Iterator<Item = &'a T>> IteratorOfReferencesToTupleWithF<'a, T, U> for I { } @@ -97,17 +97,6 @@ pub trait Pick<const N: usize>: Tupl { fn depict(self) -> (Self::L, Self::At, Self::R); } -pub trait RefIze { - type AsRef<'a> - where - Self: 'a; - type AsMut<'a> - where - Self: 'a; - fn as_ref(&self) -> Self::AsRef<'_>; - fn as_mut(&mut self) -> Self::AsMut<'_>; -} - pub trait RePick<const N: usize, T>: Pick<N> + Sized { type New: Tupl; fn unpick(l: Self::L, at: T, r: Self::R) -> Self::New; @@ -203,6 +192,16 @@ pub trait Tupl: core::marker::Tuple { inner: Self::Inner, last: Self::Last, ) -> Self; + + type AsRef<'a> + where + Self: 'a; + fn as_ref(&self) -> Self::AsRef<'_>; + type AsMut<'a> + where + Self: 'a; + fn as_mut(&mut self) -> Self::AsMut<'_>; + /// reconstruct; dont use directly fn cons(head: Self::Head, tail: Self::Tail) -> Self; /// retcurtsnoc; dont use directly |