forked from rust-lang/rustfmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
79 lines (67 loc) · 2.04 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#![deny(rust_2018_idioms)]
#![warn(unreachable_pub)]
#![feature(cell_leak)]
#[macro_use]
extern crate log;
#[cfg(test)]
#[macro_use]
extern crate lazy_static;
use std::path::PathBuf;
pub use crate::config::{
load_config, CliOptions, Config, Edition, FileLines, FileName, NewlineStyle, Range,
};
pub use crate::emitter::rustfmt_diff::{ModifiedChunk, ModifiedLines};
pub use crate::format_report_formatter::{FormatReportFormatter, FormatReportFormatterBuilder};
pub use crate::formatting::report::{FormatReport, FormatResult};
pub(crate) use crate::formatting::format_input_inner;
use crate::{emitter::Verbosity, result::OperationError};
#[cfg(feature = "config")]
pub mod config;
#[cfg(feature = "emitter")]
pub mod emitter;
mod format_report_formatter;
mod formatting;
mod release_channel;
pub mod result;
#[cfg(test)]
mod test;
/// Configures how rustfmt operates during formatting.
#[derive(Clone, Copy, Default)]
pub struct OperationSetting {
/// If set to `true`, format sub-modules which are defined in the given input.
pub recursive: bool,
pub verbosity: Verbosity,
}
/// The main entry point for Rustfmt. Formats the given input according to the
/// given config. `out` is only necessary if required by the configuration.
pub fn format(
input: Input,
config: &Config,
operation_setting: OperationSetting,
) -> Result<FormatReport, OperationError> {
format_input_inner(
input,
config,
operation_setting,
/* is_macro_def */ false,
)
}
pub fn format_inputs<'a>(
inputs: impl Iterator<Item = (Input, &'a Config)>,
operation_setting: OperationSetting,
) -> Result<FormatReport, OperationError> {
let mut format_report = FormatReport::new();
for (input, config) in inputs {
let report = format(input, config, operation_setting)?;
format_report.merge(report);
}
Ok(format_report)
}
/// The input to rustfmt.
#[derive(Debug)]
pub enum Input {
/// A file on the filesystem.
File(PathBuf),
/// A UTF-8 string, in many cases from stdin.
Text(String),
}