Skip to content

Commit

Permalink
fix invalid option replace operation
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Aug 31, 2024
1 parent d52db38 commit b1bf354
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ impl<T: Persisting> Persistence<T> {
autosave: bool,
) -> Result<T, PersistenceError> {
let mut obj: T = provider.load()?;
let mut me = Self {
obj.as_mut_persistence().replace(Self {
dirty: false,
autosave,
provider: Box::new(provider),
};
obj.persistence_mut().replace(&mut me);
});
Ok(obj)
}
}
Expand All @@ -54,6 +53,8 @@ pub trait Persisting: Sized {

fn persistence_mut(&mut self) -> Option<&mut Persistence<Self>>;

fn as_mut_persistence(&mut self) -> &mut Option<Persistence<Self>>;

fn is_persisted(&self) -> bool { self.persistence().is_some() }

fn is_dirty(&self) -> bool { self.persistence().map(|p| p.autosave).unwrap_or(true) }
Expand Down Expand Up @@ -93,13 +94,12 @@ pub trait Persisting: Sized {
autosave: bool,
) -> Result<bool, PersistenceError> {
let was_persisted = self.is_persisted();
let mut me = Persistence {
self.mark_dirty();
self.as_mut_persistence().replace(Persistence {
dirty: false,
autosave,
provider: Box::new(provider),
};
self.persistence_mut().replace(&mut me);
self.mark_dirty();
});
Ok(was_persisted)
}

Expand Down

0 comments on commit b1bf354

Please sign in to comment.