fn format_project<T: FormatHandler>(
    input: Input,
    config: &Config,
    handler: &mut T,
    is_macro_def: bool,
) -> Result<FormatReport, ErrorKind> {
    let mut timer = Timer::start();

    let main_file = input.file_name();
    let input_is_stdin = main_file == FileName::Stdin;

    let parse_session = ParseSess::new(config)?;
    if config.skip_children() && parse_session.ignore_file(&main_file) {
        return Ok(FormatReport::new());
    }

    // Parse the crate.
    let mut report = FormatReport::new();
    let directory_ownership = input.to_directory_ownership();
    let krate = match Parser::parse_crate(input, &parse_session) {
        Ok(krate) => krate,
        // Surface parse error via Session (errors are merged there from report)
        Err(e) => {
            let forbid_verbose = input_is_stdin || e != ParserError::ParsePanicError;
            should_emit_verbose(forbid_verbose, config, || {
                eprintln!("The Rust parser panicked");
            });
            report.add_parsing_error();
            return Ok(report);
        }
    };

    let mut context = FormatContext::new(&krate, report, parse_session, config, handler);
    let files = modules::ModResolver::new(
        &context.parse_session,
        directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaBlock),
        !input_is_stdin && !config.skip_children(),
    )
    .visit_crate(&krate)?;

    timer = timer.done_parsing();

    // Suppress error output if we have to do any further parsing.
    context.parse_session.set_silent_emitter();

    for (path, module) in files {
        let source_file = context.parse_session.span_to_file_contents(module.span);
        let src = source_file.src.as_ref().expect("SourceFile without src");

        let should_ignore = (!input_is_stdin && context.ignore_file(&path))
            || (!config.format_generated_files() && is_generated_file(src));

        if (config.skip_children() && path != main_file) || should_ignore {
            continue;
        }
        should_emit_verbose(input_is_stdin, config, || println!("Formatting {}", path));
        context.format_file(path, &module, is_macro_def)?;
    }
    timer = timer.done_formatting();

    should_emit_verbose(input_is_stdin, config, || {
        println!(
            "Spent {0:.3} secs in the parsing phase, and {1:.3} secs in the formatting phase",
            timer.get_parse_time(),
            timer.get_format_time(),
        )
    });

    Ok(context.report)
}
// Format an entire crate (or subset of the module tree).
Format an entire crate (or subset of the module tree).
Format an entire crate ( or subset of the module tree ) .
fn format_project<T: FormatHandler>(
    input: Input,
    config: &Config,
    handler: &mut T,
    is_macro_def: bool,
) -> Result<FormatReport, ErrorKind> {
    let mut timer = Timer::start();
    let main_file = input.file_name();
    let input_is_stdin = main_file == FileName::Stdin;
    let parse_session = ParseSess::new(config)?;
    if config.skip_children() && parse_session.ignore_file(&main_file) {
        return Ok(FormatReport::new());
    }
    // Parse the crate.
    let mut report = FormatReport::new();
    let directory_ownership = input.to_directory_ownership();
    let krate = match Parser::parse_crate(input, &parse_session) {
        Ok(krate) => krate,
        // Surface parse error via Session (errors are merged there from report)
        Err(e) => {
            let forbid_verbose = input_is_stdin || e != ParserError::ParsePanicError;
            should_emit_verbose(forbid_verbose, config, || {
                eprintln!("The Rust parser panicked");
            });
            report.add_parsing_error();
            return Ok(report);
        }
    };
    let mut context = FormatContext::new(&krate, report, parse_session, config, handler);
    let files = modules::ModResolver::new(
        &context.parse_session,
        directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaBlock),
        !input_is_stdin && !config.skip_children(),
    )
    .visit_crate(&krate)?;
    timer = timer.done_parsing();
    // Suppress error output if we have to do any further parsing.
    context.parse_session.set_silent_emitter();
    for (path, module) in files {
        let source_file = context.parse_session.span_to_file_contents(module.span);
        let src = source_file.src.as_ref().expect("SourceFile without src");
        let should_ignore = (!input_is_stdin && context.ignore_file(&path))
            || (!config.format_generated_files() && is_generated_file(src));
        if (config.skip_children() && path != main_file) || should_ignore {
            continue;
        }
        should_emit_verbose(input_is_stdin, config, || println!("Formatting {}", path));
        context.format_file(path, &module, is_macro_def)?;
    }
    timer = timer.done_formatting();
    should_emit_verbose(input_is_stdin, config, || {
        println!(
            "Spent {0:.3} secs in the parsing phase, and {1:.3} secs in the formatting phase",
            timer.get_parse_time(),
            timer.get_format_time(),
        )
    });
    Ok(context.report)
}
fn format_project < T : FormatHandler > ( input : Input , config : & Config , handler : & mut T , is_macro_def : bool , ) -> Result < FormatReport , ErrorKind > { let mut timer = Timer :: start ( ) ; let main_file = input . file_name ( ) ; let input_is_stdin = main_file == FileName :: Stdin ; let parse_session = ParseSess :: new ( config ) ? ; if config . skip_children ( ) && parse_session . ignore_file ( & main_file ) { return Ok ( FormatReport :: new ( ) ) ; } // Parse the crate. let mut report = FormatReport :: new ( ) ; let directory_ownership = input . to_directory_ownership ( ) ; let krate = match Parser :: parse_crate ( input , & parse_session ) { Ok ( krate ) => krate , // Surface parse error via Session (errors are merged there from report) Err ( e ) => { let forbid_verbose = input_is_stdin || e != ParserError :: ParsePanicError ; should_emit_verbose ( forbid_verbose , config , | | { eprintln ! ( " " ) ; } ) ; report . add_parsing_error ( ) ; return Ok ( report ) ; } } ; let mut context = FormatContext :: new ( & krate , report , parse_session , config , handler ) ; let files = modules :: ModResolver :: new ( & context . parse_session , directory_ownership . unwrap_or ( DirectoryOwnership :: UnownedViaBlock ) , ! input_is_stdin && ! config . skip_children ( ) , ) . visit_crate ( & krate ) ? ; timer = timer . done_parsing ( ) ; // Suppress error output if we have to do any further parsing. context . parse_session . set_silent_emitter ( ) ; for ( path , module ) in files { let source_file = context . parse_session . span_to_file_contents ( module . span ) ; let src = source_file . src . as_ref ( ) . expect ( " " ) ; let should_ignore = ( ! input_is_stdin && context . ignore_file ( & path ) ) || ( ! config . format_generated_files ( ) && is_generated_file ( src ) ) ; if ( config . skip_children ( ) && path != main_file ) || should_ignore { continue ; } should_emit_verbose ( input_is_stdin , config , | | println ! ( " " path ) ) ; context . format_file ( path , & module , is_macro_def ) ? ; } timer = timer . done_formatting ( ) ; should_emit_verbose ( input_is_stdin , config , | | { println ! ( " " timer get_parse_time ( ) timer get_format_time ( ) ) } ) ; Ok ( context . report ) }
Format an entire crate (or subset of the module tree).
Format an entire crate ( or subset of the module tree ) .
input
Input
config
&Config
handler
&mut T
is_macro_def
bool
input
Input
config
&Config
handler
&mut T
is_macro_def
bool