From 0219dbb359df6933062e24c2698bb3f37be3da9b Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 23 Dec 2020 01:06:05 -0800 Subject: [PATCH] transaction: make evolution_mut() return a mutable reference This includes fixing a lifetime bound on `MutableEvolution` that was reversed. --- lib/src/evolution.rs | 2 +- lib/src/transaction.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/src/evolution.rs b/lib/src/evolution.rs index 4a4b78826..c899cf683 100644 --- a/lib/src/evolution.rs +++ b/lib/src/evolution.rs @@ -309,7 +309,7 @@ impl<'r> ReadonlyEvolution<'r> { } } -pub struct MutableEvolution<'r, 'm: 'r> { +pub struct MutableEvolution<'r: 'm, 'm> { repo: &'m MutableRepo<'r>, state: State, } diff --git a/lib/src/transaction.rs b/lib/src/transaction.rs index 3de8c6686..1e8fd6f5d 100644 --- a/lib/src/transaction.rs +++ b/lib/src/transaction.rs @@ -219,8 +219,10 @@ impl<'r> Repo for MutableRepo<'r> { } } -impl MutableRepo<'_> { - pub fn evolution_mut(&mut self) -> &MutableEvolution { - self.evolution.as_mut().unwrap() +impl<'r> MutableRepo<'r> { + pub fn evolution_mut<'m>(&'m mut self) -> &'m mut MutableEvolution<'r, 'm> { + let evolution: &mut MutableEvolution<'static, 'static> = self.evolution.as_mut().unwrap(); + let evolution: &mut MutableEvolution<'r, 'm> = unsafe { std::mem::transmute(evolution) }; + evolution } }