// 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,
) -> Result<FormatReport, ErrorKind> {
    let mut timer = Timer::start();
    let main_file = input.file_name();
    let input_is_stdin = main_file == FileName::Stdin;
    // Parse the crate.
    let source_map = Rc::new(SourceMap::new(FilePathMapping::empty()));
    let mut parse_session = make_parse_sess(source_map.clone(), config);
    let mut report = FormatReport::new();
    let directory_ownership = input.to_directory_ownership();
    let krate = match parse_crate(
        input,
        &parse_session,
        config,
        &mut report,
        directory_ownership,
    ) {
        Ok(krate) => krate,
        // Surface parse error via Session (errors are merged there from report)
        Err(ErrorKind::ParseError) => return Ok(report),
        Err(e) => return Err(e),
    };
    timer = timer.done_parsing();
    // Suppress error output if we have to do any further parsing.
    let silent_emitter = silent_emitter();
    parse_session.span_diagnostic = Handler::with_emitter(true, None, silent_emitter);
    let mut context = FormatContext::new(&krate, report, parse_session, config, handler);
    let files = modules::ModResolver::new(
        context.parse_session.source_map(),
        directory_ownership.unwrap_or(parse::DirectoryOwnership::UnownedViaMod(false)),
        input_is_stdin,
    )
    .visit_crate(&krate)
    .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
    for (path, (module, _)) in files {
        if (config.skip_children() && path != main_file) || config.ignore().skip_file(&path) {
            continue;
        }
        should_emit_verbose(input_is_stdin, config, || println!("Formatting {}", path));
        let is_root = path == main_file;
        context.format_file(path, module, is_root)?;
    }
    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 , ) -> Result < FormatReport , ErrorKind > { let mut timer = Timer :: start ( ) ; let main_file = input . file_name ( ) ; let input_is_stdin = main_file == FileName :: Stdin ; // Parse the crate. let source_map = Rc :: new ( SourceMap :: new ( FilePathMapping :: empty ( ) ) ) ; let mut parse_session = make_parse_sess ( source_map . clone ( ) , config ) ; let mut report = FormatReport :: new ( ) ; let directory_ownership = input . to_directory_ownership ( ) ; let krate = match parse_crate ( input , & parse_session , config , & mut report , directory_ownership , ) { Ok ( krate ) => krate , // Surface parse error via Session (errors are merged there from report) Err ( ErrorKind :: ParseError ) => return Ok ( report ) , Err ( e ) => return Err ( e ) , } ; timer = timer . done_parsing ( ) ; // Suppress error output if we have to do any further parsing. let silent_emitter = silent_emitter ( ) ; parse_session . span_diagnostic = Handler :: with_emitter ( true , None , silent_emitter ) ; let mut context = FormatContext :: new ( & krate , report , parse_session , config , handler ) ; let files = modules :: ModResolver :: new ( context . parse_session . source_map ( ) , directory_ownership . unwrap_or ( parse :: DirectoryOwnership :: UnownedViaMod ( false ) ) , input_is_stdin , ) . visit_crate ( & krate ) . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: Other , e ) ) ? ; for ( path , ( module , _ ) ) in files { if ( config . skip_children ( ) && path != main_file ) || config . ignore ( ) . skip_file ( & path ) { continue ; } should_emit_verbose ( input_is_stdin , config , | | println ! ( " " path ) ) ; let is_root = path == main_file ; context . format_file ( path , module , is_root ) ? ; } 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