Skip to main content

scripted_fixture_writable_with_post

Function scripted_fixture_writable_with_post 

Source
pub fn scripted_fixture_writable_with_post<T>(
    script_name: impl AsRef<Path>,
    version: u32,
    post_process: impl FnMut(FixtureState<'_>) -> PostResult<T>,
) -> Result<(TempDir, T)>
Expand description

Like scripted_fixture_writable, but runs a Rust closure after the script completes.

  • version should be incremented when the closure’s behavior changes to invalidate the cache.
  • The closure receives a FixtureState enum indicating whether the fixture is newly created (Fresh) or was loaded from cache (Cached). Both variants carry the fixture directory path.
  • For Fresh fixtures, the closure can modify the directory and compute values.
  • For Cached fixtures, the closure should only compute values without modifications.
  • The closure always runs, ensuring the returned value is always available.