mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-14 17:48:10 +00:00
Changed ConfigType trait to only return a string of variants, rather than a vec
This commit is contained in:
parent
cd9e9b5db0
commit
d773580715
@ -17,7 +17,7 @@ extern crate rustfmt;
|
||||
extern crate toml;
|
||||
|
||||
use rustfmt::{WriteMode, run};
|
||||
use rustfmt::config::{Config, ConfigHelpVariantTypes};
|
||||
use rustfmt::config::Config;
|
||||
|
||||
use std::env;
|
||||
use std::fs::{File, PathExt};
|
||||
@ -87,13 +87,7 @@ fn print_usage<S: Into<String>>(reason: S) {
|
||||
reason.into());
|
||||
|
||||
for option in Config::get_docs() {
|
||||
let variants = option.variant_names();
|
||||
let variant_names: String = match *variants {
|
||||
ConfigHelpVariantTypes::UsizeConfig => "<unsigned integer>".into(),
|
||||
ConfigHelpVariantTypes::BoolConfig => "<boolean>".into(),
|
||||
ConfigHelpVariantTypes::EnumConfig(ref variants) => variants.join(", "),
|
||||
};
|
||||
println!("{}, {}, Possible values: {}", option.option_name(), option.doc_string(), variant_names);
|
||||
println!("{}, {}, Possible values: {}", option.option_name(), option.doc_string(), option.variant_names());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,34 +82,28 @@ macro_rules! create_config {
|
||||
$(pub $i: Option<$ty>),+
|
||||
}
|
||||
|
||||
// This trait and the following impl blocks are there only so that we
|
||||
// can use UCFS inside the get_docs() function on builtin types for configs.
|
||||
trait IsConfigType {
|
||||
fn get_variant_names() -> Vec<&'static str>;
|
||||
// This trait and the following impl blocks are there so that we an use
|
||||
// UCFS inside the get_docs() function on types for configs.
|
||||
pub trait ConfigType {
|
||||
fn get_variant_names() -> String;
|
||||
}
|
||||
|
||||
impl IsConfigType for bool {
|
||||
fn get_variant_names() -> Vec<&'static str> {
|
||||
unreachable!()
|
||||
impl ConfigType for bool {
|
||||
fn get_variant_names() -> String {
|
||||
String::from("<boolean>")
|
||||
}
|
||||
}
|
||||
|
||||
impl IsConfigType for usize {
|
||||
fn get_variant_names() -> Vec<&'static str> {
|
||||
unreachable!()
|
||||
impl ConfigType for usize {
|
||||
fn get_variant_names() -> String {
|
||||
String::from("<unsigned integer>")
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ConfigHelpItem {
|
||||
option_name: &'static str,
|
||||
doc_string : &'static str,
|
||||
variant_names: ConfigHelpVariantTypes,
|
||||
}
|
||||
|
||||
pub enum ConfigHelpVariantTypes {
|
||||
UsizeConfig,
|
||||
BoolConfig,
|
||||
EnumConfig(Vec<&'static str>),
|
||||
variant_names: String,
|
||||
}
|
||||
|
||||
impl ConfigHelpItem {
|
||||
@ -121,7 +115,7 @@ macro_rules! create_config {
|
||||
self.doc_string
|
||||
}
|
||||
|
||||
pub fn variant_names(&self) -> &ConfigHelpVariantTypes {
|
||||
pub fn variant_names(&self) -> &String {
|
||||
&self.variant_names
|
||||
}
|
||||
}
|
||||
@ -165,15 +159,10 @@ macro_rules! create_config {
|
||||
pub fn get_docs() -> Vec<ConfigHelpItem> {
|
||||
let mut options: Vec<ConfigHelpItem> = Vec::new();
|
||||
$(
|
||||
let config_variant_type = match stringify!($ty) {
|
||||
"bool" => ConfigHelpVariantTypes::BoolConfig,
|
||||
"usize" => ConfigHelpVariantTypes::UsizeConfig,
|
||||
_ => ConfigHelpVariantTypes::EnumConfig(<$ty>::get_variant_names()),
|
||||
};
|
||||
options.push(ConfigHelpItem {
|
||||
option_name: stringify!($i),
|
||||
doc_string: stringify!($dstring),
|
||||
variant_names: config_variant_type,
|
||||
variant_names: <$ty>::get_variant_names(),
|
||||
});
|
||||
)+
|
||||
options
|
||||
|
@ -162,14 +162,14 @@ macro_rules! impl_enum_decodable {
|
||||
}
|
||||
}
|
||||
|
||||
impl $e {
|
||||
pub fn get_variant_names() -> Vec<&'static str> {
|
||||
impl ::config::ConfigType for $e {
|
||||
fn get_variant_names() -> String {
|
||||
let mut variants = Vec::new();
|
||||
$(
|
||||
variants.push(stringify!($x));
|
||||
)*
|
||||
|
||||
variants
|
||||
variants.join(", ")
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user