You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: builder.rs
    path of file: ./repos/foundry/crates/doc/src
    
    the code of the file until where you have to start completion: use crate::{
    document::DocumentContent, helpers::merge_toml_table, AsDoc, BufWriter, Document, ParseItem,
    ParseSource, Parser, Preprocessor,
};
use forge_fmt::{FormatterConfig, Visitable};
use foundry_common::glob::expand_globs;
use foundry_compilers::utils::source_files_iter;
use foundry_config::DocConfig;
use itertools::Itertools;
use mdbook::MDBook;
use rayon::prelude::*;
use std::{
    cmp::Ordering,
    collections::HashMap,
    fs,
    path::{Path, PathBuf},
};
use toml::value;

/// Build Solidity documentation for a project from natspec comments.
/// The builder parses the source files using [Parser],
/// then formats and writes the elements as the output.
#[derive(Debug)]
pub struct DocBuilder {
    /// The project root
    pub root: PathBuf,
    /// Path to Solidity source files.
    pub sources: PathBuf,
    /// Paths to external libraries.
    pub libraries: Vec<PathBuf>,
    /// Flag whether to build mdbook.
    pub should_build: bool,
    /// Documentation configuration.
    pub config: DocConfig,
    /// The array of preprocessors to apply.
    pub preprocessors: Vec<Box<dyn Preprocessor>>,
    /// The formatter config.
    pub fmt: FormatterConfig,
    /// Whether to include libraries to the output.
    pub include_libraries: bool,
}

// TODO: consider using `tfio`
impl DocBuilder {
    pub(crate) const SRC: &'static str = "src";
    const SOL_EXT: &'static str = "sol";
    const README: &'static str = "README.md";
    const SUMMARY: &'static str = "SUMMARY.md";

    /// Create new instance of builder.
    pub fn new(
        root: PathBuf,
        sources: PathBuf,
        libraries: Vec<PathBuf>,
        include_libraries: bool,
    ) -> Self {
        Self {
            root,
            sources,
            libraries,
            include_libraries,
            should_build: false,
            config: DocConfig::default(),
            preprocessors: Default::default(),
            fmt: Default::default(),
        }
    }

    /// Set `should_build` flag on the builder
    pub fn with_should_build(mut self, should_build: bool) -> Self {
        self.should_build = should_build;
        self
    }

    /// Set config on the builder.
    pub fn with_config(mut self, config: DocConfig) -
    
    fn write_mdbook(&self, documents: Vec<Document>) -> eyre::Result<()> {
        let out_dir = self.out_dir();
        let out_dir_src = out_dir.join(Self::SRC);
        fs::create_dir_all(&out_dir_src)?;

        // Write readme content if any
        let homepage_content = {
            // Default to the homepage README if it's available.
            // If not, use the src README as a fallback.
            let homepage_or_src_readme = self
                .config
                .homepage
                .as_ref()
                .map(|homepage| self.root.join(homepage))
                .unwrap_or_else(|| self.sources.join(Self::README));
            // Grab the root readme.
            let root_readme = self.root.join(Self::README);

            // Check to see if there is a 'homepage' option specified in config.
            // If not, fall back to src and root readme files, in that order.
            if homepage_or_src_readme.exists() {
                fs::read_to_string(homepage_or_src_readme)?
            } else if root_readme.exists() {
                fs::read_to_string(root_readme)?
            } else {
                String::new()
            }
        };

        let readme_path = out_dir_src.join(Self::README);
        fs::write(readme_path, homepage_content)?;

        // Write summary and section readmes
        let mut summary = BufWriter::default();
        summary.write_title("Summary")?;
        summary.write_link_list_item("Home", Self::README, 0)?;
        self.write_summary_section(&mut summary, &documents.iter().collect::<Vec<_>>(), None, 0)?;
        fs::write(out_dir_src.join(Self::SUMMARY), summary.finish())?;

        // Write solidity syntax highlighting
        fs::write(out_dir.join("solidity.min.js"), include_str!("../static/solidity.min.js"))?;

        // Write css files
        fs::write(out_dir.join("book.css"), include_str!("../static/book.css"))?;

        // Write book config
        fs::write(self.out_dir().join("book.toml"), self.book_config()?)?;

        // Write .gitignore
        let gitignore = "book/";
        fs::write(self.out_dir().join(".gitignore"), gitignore)?;

        // Write doc files
        for document in documents {
            fs::create_dir_all(
                document
                    .target_path
                    .parent()
                    .ok_or_else(|| eyre::format_err!("empty target path; noop"))?,
            )?;
            fs::write(&document.target_path, document.as_doc()?)?;
        }

        Ok(())
    }