Skip to main content

process_file_with_context

Function process_file_with_context 

Source
pub fn process_file_with_context<T, F>(
    path: &Path,
    parent_ctx: &ParallelContext,
    f: F,
) -> T
where F: FnOnce() -> T,
Expand description

Process a file with full context setup.

This combines:

  1. Entering the parent context (span + analysis context)
  2. Setting the current file in context
  3. Creating a debug span for the file
  4. Incrementing the processed count

Use this for the common pattern of processing files in parallel.

§Arguments

  • path - The file being processed
  • parent_ctx - The context captured from the parent thread
  • f - The closure to execute

§Example

let ctx = ParallelContext::capture();

files.par_iter().map(|path| {
    process_file_with_context(path, &ctx, || {
        // If panic here, crash report shows:
        // - Phase from parent context
        // - File: /path/to/current/file.rs
        // - Span: parent_span > process_file
        analyze_file(path)
    })
}).collect()