mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-11 16:15:03 +00:00
Use impl_enum_decodable for SeparatorTactic
This commit is contained in:
parent
55f2de9cf1
commit
adedba45a8
18
src/lib.rs
18
src/lib.rs
@ -53,6 +53,7 @@ mod visitor;
|
||||
mod items;
|
||||
mod missed_spans;
|
||||
mod lists;
|
||||
#[macro_use]
|
||||
mod utils;
|
||||
mod types;
|
||||
mod expr;
|
||||
@ -64,23 +65,6 @@ const SKIP_ANNOTATION: &'static str = "rustfmt_skip";
|
||||
|
||||
static mut CONFIG: Option<config::Config> = None;
|
||||
|
||||
// Macro for deriving implementations of Decodable for enums
|
||||
macro_rules! impl_enum_decodable {
|
||||
( $e:ident, $( $x:ident ),* ) => {
|
||||
impl Decodable for $e {
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> {
|
||||
let s = try!(d.read_str());
|
||||
match &*s {
|
||||
$(
|
||||
stringify!($x) => Ok($e::$x),
|
||||
)*
|
||||
_ => Err(d.error("Bad variant")),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum WriteMode {
|
||||
Overwrite,
|
||||
|
13
src/lists.rs
13
src/lists.rs
@ -30,18 +30,7 @@ pub enum SeparatorTactic {
|
||||
Vertical,
|
||||
}
|
||||
|
||||
// TODO could use a macro for all these Decodable impls.
|
||||
impl Decodable for SeparatorTactic {
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> {
|
||||
let s = try!(d.read_str());
|
||||
match &*s {
|
||||
"Always" => Ok(SeparatorTactic::Always),
|
||||
"Never" => Ok(SeparatorTactic::Never),
|
||||
"Vertical" => Ok(SeparatorTactic::Vertical),
|
||||
_ => Err(d.error("Bad variant")),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl_enum_decodable!(SeparatorTactic, Always, Never, Vertical);
|
||||
|
||||
// TODO having some helpful ctors for ListFormatting would be nice.
|
||||
pub struct ListFormatting<'a> {
|
||||
|
19
src/utils.rs
19
src/utils.rs
@ -47,3 +47,22 @@ pub fn format_visibility(vis: Visibility) -> &'static str {
|
||||
Visibility::Inherited => ""
|
||||
}
|
||||
}
|
||||
|
||||
// Macro for deriving implementations of Decodable for enums
|
||||
#[macro_export]
|
||||
macro_rules! impl_enum_decodable {
|
||||
( $e:ident, $( $x:ident ),* ) => {
|
||||
impl Decodable for $e {
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> {
|
||||
let s = try!(d.read_str());
|
||||
match &*s {
|
||||
$(
|
||||
stringify!($x) => Ok($e::$x),
|
||||
)*
|
||||
_ => Err(d.error("Bad variant")),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user