Solve the EntryLayer problem by removing that Trait and hardcoded implementing it for the few structs.

Not perfect, not rust-ly nice, but i have the feeling that rust needs some more time to counter this pattern. However it even occurs with stable features (the Lifetime of C,I and T as you see in the previous commit)
I have found: https://matklad.github.io/2018/05/04/encapsulating-lifetime-of-the-field.html which looks like it might be related to my problem. but i am not yet sure, anyway, problem solved for now, future will tell
This commit is contained in:
Marcel Märtens 2019-11-19 12:32:28 +01:00
parent 497b5528bf
commit a4a5cf048e
3 changed files with 39 additions and 44 deletions

View File

@ -313,4 +313,28 @@ pub mod tests {
}
b.iter(|| x.trav(access).get().get().get().mat());
}
/*
pub struct MyIterMut<'a, C> {
pub( super ) layer: &'a mut C,
}
#[derive(Default, Clone)]
pub struct Layer<C> {
pub child: C,
}
pub trait EntryPoint {
type TRAV_MUT<'a>;
fn trav_mut<'a>(&'a mut self, pos: LodPos) -> Self::TRAV_MUT;
}
impl<C> EntryPoint
for Layer<C>
{
type TRAV_MUT<'a> = MyIterMut<'a, Layer<C>>;
fn trav_mut<'a>(&'a mut self, pos: u8) -> Self::TRAV_MUT {
MyIterMut {
layer: self,
}
}
}*/
}

View File

@ -33,7 +33,7 @@ pub struct VecNestDelta<D: DeltaStore, T, const L: u8> {
pub child: D,
}
pub struct DeltaWriter<'a, C: EntryLayer + DetailStore, D: EntryLayer + DeltaStore> {
pub struct DeltaWriter<'a, C: DetailStore, D: DeltaStore> {
pub delta: &'a mut D,
pub data: &'a mut C,
}
@ -53,7 +53,7 @@ pub struct DataWriterIter<DT, CT> {
//#######################################################
impl<'a, C: DetailStore + EntryLayer, D: DeltaStore + EntryLayer> DeltaWriter<'a, C, D> {
impl<'a, C: DetailStore, D: DeltaStore> DeltaWriter<'a, C, D> {
pub fn new(delta: &'a mut D, data: &'a mut C) -> Self {
DeltaWriter { delta, data }
}
@ -187,7 +187,7 @@ mod stests {
let mut d = ExampleDelta::default();
{
let mut w = DeltaWriter::new(&mut d, &mut x);
//b.iter(|| w.trav_mut(LodPos::xyz(0, 0, 0)));
b.iter(|| {w.trav_mut(LodPos::xyz(0, 0, 0));});
}
}
@ -197,7 +197,7 @@ mod stests {
let mut d = ExampleDelta::default();
{
let mut w = DeltaWriter::new(&mut d, &mut x);
//b.iter(|| w.trav_mut(LodPos::xyz(0, 0, 0)).get().get().get().mat());
b.iter(|| {w.trav_mut(LodPos::xyz(0, 0, 0)).get().get().get().mat();});
}
}
@ -222,7 +222,7 @@ mod stests {
let mut d = ExampleDelta::default();
{
let mut w = DeltaWriter::new(&mut d, &mut x);
//b.iter(|| {w.trav_mut_xxx(LodPos::xyz(0, 0, 0));});
b.iter(|| {w.trav_mut(LodPos::xyz(0, 0, 0));});
}
}
/*

View File

@ -4,6 +4,7 @@ use super::data::{HashNestLayer, DetailStore, HashIter, HashIterMut};
use super::delta::{VecNestDelta, DeltaStore, VecDeltaIter, VecDeltaIterMut, DataWriterIter, DeltaWriter};
use super::traversable::Traversable;
//TODO: actually implement EntryLayer
pub trait EntryLayer {
type TRAV<'a>: Traversable;
type TRAV_MUT<'a>: Traversable;
@ -12,15 +13,9 @@ pub trait EntryLayer {
}
///////////////// data types
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> EntryLayer
for HashNestLayer<C, T, I, { L }>
impl<C: DetailStore, T, I: ToOptionUsize, const L: u8> HashNestLayer<C, T, I, { L }>
{
type TRAV<'a> = HashIter<'a, HashNestLayer<C, T, I, { L }>>;
type TRAV_MUT<'a> = HashIterMut<'a, HashNestLayer<C, T, I, { L }>>;
//ERROR make the HashIter C: remove the &'a from HashIter coding and implement it here
fn trav<'a>(&'a self, pos: LodPos) -> HashIter<'a, HashNestLayer<C, T, I, { L }>> {
pub fn trav<'a>(&'a self, pos: LodPos) -> HashIter<'a, HashNestLayer<C, T, I, { L }>> {
HashIter {
layer: self,
wanted: pos,
@ -28,7 +23,7 @@ for HashNestLayer<C, T, I, { L }>
}
}
fn trav_mut<'a>(&'a mut self, pos: LodPos) -> Self::TRAV_MUT {
pub fn trav_mut<'a>(&'a mut self, pos: LodPos) -> HashIterMut<'a, HashNestLayer<C, T, I, { L }>> {
HashIterMut {
layer: self,
wanted: pos,
@ -38,49 +33,25 @@ for HashNestLayer<C, T, I, { L }>
}
///////////////// delta types
impl<D: DeltaStore, T, const L: u8> EntryLayer for VecNestDelta<D, T, { L }> {
type TRAV<'a> = VecDeltaIter<'a, VecNestDelta<D, T, { L }>>;
type TRAV_MUT<'a> = VecDeltaIterMut<'a, VecNestDelta<D, T, { L }>>;
fn trav<'a>(&'a self, _pos: LodPos) -> Self::TRAV {
impl<D: DeltaStore, T, const L: u8> VecNestDelta<D, T, { L }> {
pub fn trav<'a>(&'a self, _pos: LodPos) -> VecDeltaIter<'a, VecNestDelta<D, T, { L }>> {
VecDeltaIter { layer: self }
}
fn trav_mut<'a>(&'a mut self, _pos: LodPos) -> Self::TRAV_MUT {
pub fn trav_mut<'a>(&'a mut self, _pos: LodPos) -> VecDeltaIterMut<'a, VecNestDelta<D, T, { L }>> {
VecDeltaIterMut { layer: self }
}
}
impl<C: DetailStore + EntryLayer, D: DeltaStore + EntryLayer> EntryLayer
for DeltaWriter<'_, C, D>
where
<<C as EntryLayer>::TRAV as Traversable>::TRAV_CHILD: Traversable,
<<D as EntryLayer>::TRAV as Traversable>::TRAV_CHILD: Traversable,
impl<D: DeltaStore, C: DetailStore, T, I: ToOptionUsize, const L: u8> DeltaWriter<'_, HashNestLayer<C, T, I, { L }>, VecNestDelta<D, T, { L }>>
{
type TRAV<'a> = DataWriterIter<D::TRAV, C::TRAV>;
type TRAV_MUT<'a> = DataWriterIter<D::TRAV_MUT, C::TRAV_MUT>;
fn trav<'a>(&'a self, pos: LodPos) -> Self::TRAV {
pub fn trav<'a>(&'a self, pos: LodPos) -> DataWriterIter<VecDeltaIter<'a, VecNestDelta<D, T, { L }>>, HashIter<'a, HashNestLayer<C, T, I, { L }>>> {
DataWriterIter {
delta_iter: self.delta.trav(pos),
data_iter: self.data.trav(pos),
}
}
fn trav_mut<'a>(&'a mut self, pos: LodPos) -> Self::TRAV_MUT {
DataWriterIter {
delta_iter: self.delta.trav_mut(pos),
data_iter: self.data.trav_mut(pos),
}
}
}
impl<'a, C: DetailStore + EntryLayer, D: DeltaStore + EntryLayer> DeltaWriter<'a, C, D>
where
<<C as EntryLayer>::TRAV as Traversable>::TRAV_CHILD: Traversable,
<<D as EntryLayer>::TRAV as Traversable>::TRAV_CHILD: Traversable,
{
pub fn trav_mut_xxx(&mut self, pos: LodPos) -> DataWriterIter<D::TRAV_MUT, C::TRAV_MUT> {
pub fn trav_mut<'a>(&'a mut self, pos: LodPos) -> DataWriterIter< VecDeltaIterMut<'a, VecNestDelta<D, T, { L }>>, HashIterMut<'a, HashNestLayer<C, T, I, { L }>>> {
DataWriterIter {
delta_iter: self.delta.trav_mut(pos),
data_iter: self.data.trav_mut(pos),