[no description]
Diffstat (limited to 'src/implementations.rs')
-rw-r--r--src/implementations.rs42
1 files changed, 42 insertions, 0 deletions
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: ]