Skip to content

Commit

Permalink
Move implementation of extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Aug 29, 2024
1 parent 188d47f commit 3d20fcd
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions turbopack/crates/turbo-tasks/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,31 +259,28 @@ pub trait TurboTasksBackendApiExt<B: Backend + 'static>: TurboTasksBackendApi<B>
///
/// This function holds open a non-exclusive read lock that blocks writes, so `func` is expected
/// to execute quickly in order to release the lock.
fn read_task_state<T>(&self, func: impl FnOnce(&B::TaskState) -> T) -> T;
fn read_task_state<T>(&self, func: impl FnOnce(&B::TaskState) -> T) -> T {
let mut out = None;
self.read_task_state_boxed(Box::new(|ts| out = Some(func(ts))));
out.expect("write_task_state_boxed must call `func`")
}

/// Allows modification of the [`Backend::TaskState`].
///
/// This function holds open a write lock, so `func` is expected to execute quickly in order to
/// release the lock.
fn write_task_state<T>(&self, func: impl FnOnce(&mut B::TaskState) -> T) -> T;
fn write_task_state<T>(&self, func: impl FnOnce(&mut B::TaskState) -> T) -> T {
let mut out = None;
self.write_task_state_boxed(Box::new(|ts| out = Some(func(ts))));
out.expect("write_task_state_boxed must call `func`")
}
}

impl<TT, B> TurboTasksBackendApiExt<B> for TT
where
TT: TurboTasksBackendApi<B> + ?Sized,
B: Backend + 'static,
{
fn read_task_state<T>(&self, func: impl FnOnce(&B::TaskState) -> T) -> T {
let mut out = None;
self.read_task_state_boxed(Box::new(|ts| out = Some(func(ts))));
out.expect("write_task_state_boxed must call `func`")
}

fn write_task_state<T>(&self, func: impl FnOnce(&mut B::TaskState) -> T) -> T {
let mut out = None;
self.write_task_state_boxed(Box::new(|ts| out = Some(func(ts))));
out.expect("write_task_state_boxed must call `func`")
}
}

#[allow(clippy::manual_non_exhaustive)]
Expand Down

0 comments on commit 3d20fcd

Please sign in to comment.