Repository: bevyengine/bevy
File: tools/export-content/src/app.rs (Rust)

Code before:
    let re = Regex::new(r"(?s)^---\s*\n(.*?)\n---\n(.*)").unwrap();

    let mut entries = vec![];

    for dir_entry in fs::read_dir(dir)
        .into_diagnostic()
        .wrap_err("unable to read directory")?
    {
        let dir_entry = dir_entry
            .into_diagnostic()
            .wrap_err(format!("unable to access {} file", kind))?;

        // Skip directories
        if !dir_entry.path().is_file() {
            continue;
        }
        // Skip files with invalid names
        let Ok(file_name) = dir_entry.file_name().into_string() else {
            continue;
        };
        // Skip hidden files (like .gitkeep or .DS_Store)
        if file_name.starts_with(".") {
            continue;
        }

        let file_content = fs::read_to_string(&dir_entry.path())
            .into_diagnostic()
            .wrap_err(format!("unable to read {} file", kind))?;

        let caps = re.captures(&file_content).ok_or(diagnostic!(
            "failed to find frontmatter in {} file {}",
            kind,
            file_name
        ))?;

        let frontmatter = caps.get(1).unwrap().as_str();
        let metadata = serde_yml::from_str::<Metadata>(frontmatter).map_err(|e| ParseError {
            src: frontmatter.to_owned(),
            kind,
            file_name,
            err_span: e.location().map(|l| l.index()),
            error: e,
        })?;
        let content = caps.get(2).unwrap().as_str().to_owned();

        entries.push(Entry::File { metadata, content })
    }

    Ok(entries)
}


Review comment (suggestion):
nit: needless borrow
```suggestion
        let file_content = fs::read_to_string(dir_entry.path())
```

Code after:
    let mut entries = vec![];

    for dir_entry in fs::read_dir(dir)
        .into_diagnostic()
        .wrap_err("unable to read directory")?
    {
        let dir_entry = dir_entry
            .into_diagnostic()
            .wrap_err(format!("unable to access {} file", kind))?;

        // Skip directories
        if !dir_entry.path().is_file() {
            continue;
        }
        // Skip files with invalid names
        let Ok(file_name) = dir_entry.file_name().into_string() else {
            continue;
        };
        // Skip hidden files (like .gitkeep or .DS_Store)
        if file_name.starts_with(".") {
            continue;
        }

        let file_content = fs::read_to_string(dir_entry.path())
            .into_diagnostic()
            .wrap_err(format!("unable to read {} file", kind))?;

        let caps = re.captures(&file_content).ok_or(diagnostic!(
            "failed to find frontmatter in {} file {}",
            kind,
            file_name
        ))?;

        let frontmatter = caps.name("frontmatter").unwrap().as_str();
        let metadata = serde_yml::from_str::<Metadata>(frontmatter).map_err(|e| ParseError {
            src: NamedSource::new(
                format!("{}", dir_entry.path().display()),
                frontmatter.to_owned(),
            ),
            kind,
            file_name,
            err_span: e.location().map(|l| l.index()),
            error: e,
        })?;
        let content = caps.name("content").unwrap().as_str().to_owned();

        entries.push(Entry::File { metadata, content });
    }

    Ok(entries)
}