pub struct Upsert { pub current: T, pub previous: Option, } impl Upsert { pub fn try_map(self, mut f: impl FnMut(T) -> Result) -> Result, E> { Ok(Upsert { current: f(self.current)?, previous: match self.previous { Some(value) => Some(f(value)?), None => None, }, }) } }