2015-05-23 22:25:36 +12:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
extern crate toml;
|
|
|
|
|
2015-07-16 10:44:43 +12:00
|
|
|
use {NewlineStyle, BraceStyle, ReturnIndent, StructLitStyle};
|
2015-06-09 01:42:29 +02:00
|
|
|
use lists::SeparatorTactic;
|
|
|
|
use issues::ReportTactic;
|
|
|
|
|
2015-07-20 23:29:25 +02:00
|
|
|
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
|
|
|
pub enum BlockIndentStyle {
|
|
|
|
// Same level as parent.
|
|
|
|
Inherit,
|
|
|
|
// One level deeper than parent.
|
|
|
|
Tabbed,
|
|
|
|
// Aligned with block open.
|
|
|
|
Visual,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_enum_decodable!(BlockIndentStyle, Inherit, Tabbed, Visual);
|
|
|
|
|
2015-06-23 13:26:04 +02:00
|
|
|
#[derive(RustcDecodable, Clone)]
|
2015-05-23 22:25:36 +12:00
|
|
|
pub struct Config {
|
|
|
|
pub max_width: usize,
|
|
|
|
pub ideal_width: usize,
|
|
|
|
pub leeway: usize,
|
|
|
|
pub tab_spaces: usize,
|
2015-06-09 01:42:29 +02:00
|
|
|
pub newline_style: NewlineStyle,
|
|
|
|
pub fn_brace_style: BraceStyle,
|
|
|
|
pub fn_return_indent: ReturnIndent,
|
2015-05-25 16:02:38 +02:00
|
|
|
pub fn_args_paren_newline: bool,
|
2015-06-23 15:58:58 +02:00
|
|
|
pub struct_trailing_comma: SeparatorTactic,
|
2015-06-09 01:42:29 +02:00
|
|
|
pub struct_lit_trailing_comma: SeparatorTactic,
|
2015-07-16 10:44:43 +12:00
|
|
|
pub struct_lit_style: StructLitStyle,
|
2015-05-29 12:41:26 +02:00
|
|
|
pub enum_trailing_comma: bool,
|
2015-06-09 01:42:29 +02:00
|
|
|
pub report_todo: ReportTactic,
|
|
|
|
pub report_fixme: ReportTactic,
|
2015-06-26 03:29:54 +02:00
|
|
|
pub reorder_imports: bool, // Alphabetically, case sensitive.
|
2015-07-20 23:29:25 +02:00
|
|
|
pub expr_indent_style: BlockIndentStyle,
|
2015-05-23 22:25:36 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Config {
|
2015-06-23 13:26:04 +02:00
|
|
|
pub fn from_toml(toml: &str) -> Config {
|
2015-05-23 22:25:36 +12:00
|
|
|
let parsed = toml.parse().unwrap();
|
2015-07-16 10:44:43 +12:00
|
|
|
match toml::decode(parsed) {
|
|
|
|
Some(decoded) => decoded,
|
|
|
|
None => {
|
|
|
|
println!("Decoding config file failed. Config:\n{}", toml);
|
|
|
|
let parsed: toml::Value = toml.parse().unwrap();
|
|
|
|
println!("\n\nParsed:\n{:?}", parsed);
|
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
}
|
2015-05-23 22:25:36 +12:00
|
|
|
}
|
|
|
|
}
|