Skip to content

Commit

Permalink
Merge pull request #1450 from hannobraun/partial
Browse files Browse the repository at this point in the history
Improve usability of `Partial`
  • Loading branch information
hannobraun authored Dec 14, 2022
2 parents 518281a + 2d0ecd8 commit d460cf6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions crates/fj-kernel/src/partial/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<T: HasPartial + 'static> Partial<T> {
/// # Panics
///
/// Panics, if this method is called while the return value from a previous
/// call is still borrowed.
/// call to this method of [`Self::read`] is still borrowed.
pub fn write(&mut self) -> impl DerefMut<Target = T::Partial> + '_ {
let mut inner = self.inner.write();

Expand All @@ -91,7 +91,7 @@ impl<T: HasPartial + 'static> Partial<T> {
///
/// # Panics
///
/// Panics, if a return value of [`Self::write`] is still borrowed.
/// Panics, if a call to [`Self::write`] would panic.
pub fn build(self, objects: &mut Service<Objects>) -> Handle<T>
where
T: Insert,
Expand Down Expand Up @@ -168,13 +168,15 @@ impl<T: HasPartial> Inner<T> {
}

fn read(&self) -> RwLockReadGuard<InnerObject<T>> {
self.0.read()
self.0
.try_read()
.expect("Tried to read `Partial` that is currently being modified")
}

fn write(&self) -> RwLockWriteGuard<InnerObject<T>> {
self.0
.try_write()
.expect("Tried to modify `Partial` that is already being modified")
.expect("Tried to modify `Partial` that is currently locked")
}
}

Expand Down

0 comments on commit d460cf6

Please sign in to comment.