Simplify code: fewer lifetimes, auto-impl VecFrozenVersion

This commit is contained in:
Egor Suvorov
2022-11-24 02:11:06 +02:00
parent c250c2664b
commit cc2b3c986c
3 changed files with 12 additions and 8 deletions

View File

@@ -48,11 +48,20 @@ pub trait VecReadableVersion<Modification: RangeModification<Key>, Key> {
fn get(&self, keys: Range<Key>) -> Modification::Result;
}
// TODO: use trait alias when stabilized
pub trait VecFrozenVersion<Modification: RangeModification<Key>, Key>:
Clone + VecReadableVersion<Modification, Key>
{
}
impl<
T: Clone + VecReadableVersion<Modification, Key>,
Modification: RangeModification<Key>,
Key,
> VecFrozenVersion<Modification, Key> for T
{
}
pub trait PersistentVecStorage<
Modification: RangeModification<Key>,
Initializer: LazyRangeInitializer<Modification::Result, Key>,

View File

@@ -1,6 +1,6 @@
use crate::{
LazyRangeInitializer, PersistentVecStorage, RangeModification, RangeQueryResult,
VecFrozenVersion, VecReadableVersion,
VecReadableVersion,
};
use std::marker::PhantomData;
use std::ops::Range;
@@ -42,7 +42,7 @@ impl<Modification: RangeModification<Key>, Key: IndexableKey> VecReadableVersion
}
// Manual implementation of `Clone` becase `derive` requires `Modification: Clone`
impl<'a, Modification: RangeModification<Key>, Key: Clone> Clone
impl<Modification: RangeModification<Key>, Key: Clone> Clone
for NaiveFrozenVersion<Modification, Key>
{
fn clone(&self) -> Self {
@@ -53,11 +53,6 @@ impl<'a, Modification: RangeModification<Key>, Key: Clone> Clone
}
}
impl<'a, Modification: RangeModification<Key>, Key: IndexableKey>
VecFrozenVersion<Modification, Key> for NaiveFrozenVersion<Modification, Key>
{
}
// TODO: is it at all possible to store previous versions in this struct,
// without any Rc<>?
pub struct NaiveVecStorage<

View File

@@ -90,7 +90,7 @@ where
}
}
fn apply<'a>(&self, result: &'a mut SumResult<T>, range: &Range<Key>) {
fn apply(&self, result: &mut SumResult<T>, range: &Range<Key>) {
use AddAssignModification::*;
match self {
None => {}