Repository: tailwindlabs/tailwindcss
File: oxide/crates/core/src/lib.rs (Rust)

Code before:
#[tracing::instrument(skip(input, options))]
pub fn scan_files(input: Vec<ChangedContent>, options: u8) -> Vec<String> {
    match (IO::from(options), Parsing::from(options)) {
        (IO::Sequential, Parsing::Sequential) => parse_all_blobs_sync(read_all_files_sync(input)),
        (IO::Sequential, Parsing::Parallel) => parse_all_blobs(read_all_files_sync(input)),
        (IO::Parallel, Parsing::Sequential) => parse_all_blobs_sync(read_all_files(input)),
        (IO::Parallel, Parsing::Parallel) => parse_all_blobs(read_all_files(input)),
    }
}

fn read_changed_content(c: ChangedContent) -> Option<Vec<u8>> {
    match (c.file, c.content) {
        (Some(file), None) => match std::fs::read(&file) {
            Ok(content) => match file.extension().map(|x| x.to_str()) {
                Some(Some("svelte")) => Some(content.replace(" class:", " ")),
                _ => Some(content),
            },
            Err(e) => {
                event!(tracing::Level::ERROR, "Failed to read file: {:?}", e);
                Default::default()
            }
        },
        (None, Some(content)) => Some(content.into_bytes()),
        _ => Default::default(),
    }
}

#[tracing::instrument(skip(changed_content))]
fn read_all_files(changed_content: Vec<ChangedContent>) -> Vec<Vec<u8>> {
    event!(
        tracing::Level::INFO,
        "Reading {:?} file(s)",
        changed_content.len()
    );

    changed_content
        .into_par_iter()
        .filter_map(read_changed_content)
        .collect()
}

#[tracing::instrument(skip(changed_content))]
fn read_all_files_sync(changed_content: Vec<ChangedContent>) -> Vec<Vec<u8>> {
    event!(
        tracing::Level::INFO,
        "Reading {:?} file(s)",
        changed_content.len()
    );

    changed_content
        .into_iter()

Review comment (bug):
The triple nested match feels a bit weird here. It's _shorter_ but harder to fallow. All but one of these conditions are early-returnable so maybe something like this instead:
```suggestion
fn read_changed_content(c: ChangedContent) -> Option<Vec<u8>> {
  if let Some(content) = c.content {
    return Some(content.into_bytes())
  }

  let Some(file) = c.file else {
    return Default::default()
  }
  
  let Ok(content) = std::fs::read(&file) else {
    event!(tracing::Level::ERROR, "Failed to read file: {:?}", e);
    return Default::default()
  }
  
   match file.extension().map(|x| x.to_str()) {
    Some(Some("svelte")) => Some(content.replace(" class:", " ")),
    _ => Some(content),
  }
}
```


Code after:
#[tracing::instrument(skip(input, options))]
pub fn scan_files(input: Vec<ChangedContent>, options: u8) -> Vec<String> {
    match (IO::from(options), Parsing::from(options)) {
        (IO::Sequential, Parsing::Sequential) => parse_all_blobs_sync(read_all_files_sync(input)),
        (IO::Sequential, Parsing::Parallel) => parse_all_blobs(read_all_files_sync(input)),
        (IO::Parallel, Parsing::Sequential) => parse_all_blobs_sync(read_all_files(input)),
        (IO::Parallel, Parsing::Parallel) => parse_all_blobs(read_all_files(input)),
    }
}

fn read_changed_content(c: ChangedContent) -> Option<Vec<u8>> {
    if let Some(content) = c.content {
        return Some(content.into_bytes());
    }

    let Some(file) = c.file else {
        return Default::default();
    };

    let Ok(content) = std::fs::read(&file).map_err(|e| {
        event!(tracing::Level::ERROR, "Failed to read file: {:?}", e);
        e
    }) else {
        return Default::default();
    };

    let Some(extension) = file.extension().map(|x| x.to_str()) else {
        return Some(content);
    };

    match extension {
        Some("svelte") => Some(content.replace(" class:", " ")),
        _ => Some(content),
    }
}

#[tracing::instrument(skip(changed_content))]
fn read_all_files(changed_content: Vec<ChangedContent>) -> Vec<Vec<u8>> {
    event!(
        tracing::Level::INFO,
        "Reading {:?} file(s)",
        changed_content.len()
    );

    changed_content
        .into_par_iter()
        .filter_map(read_changed_content)
        .collect()
}

#[tracing::instrument(skip(changed_content))]