Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve usability of Partial #1450

Merged
merged 3 commits into from
Dec 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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