Skip to content

Commit

Permalink
Replaced parse_str_to_type call with syn::parse_str.
Browse files Browse the repository at this point in the history
  • Loading branch information
azriel91 committed Oct 17, 2018
1 parent 46db15c commit f1abbef
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl Field {
"bound" => try!(parse_bound(&mut out.clone.bounds, opt_string_to_str!(value))),
"clone_with" => {
let path = try!(opt_string_to_str!(value).ok_or_else(|| "`clone_with` needs a value".to_string()));
out.clone.clone_with = Some(try!(parse_str_to_type::<syn::Path>(&path)));
out.clone.clone_with = Some(try!(parse_str(&path)));
}
}
}
Expand All @@ -396,7 +396,7 @@ impl Field {
"bound" => try!(parse_bound(&mut out.debug.bounds, opt_string_to_str!(value))),
"format_with" => {
let path = try!(opt_string_to_str!(value).ok_or_else(|| "`format_with` needs a value".to_string()));
out.debug.format_with = Some(try!(parse_str_to_type::<syn::Path>(&path)));
out.debug.format_with = Some(try!(parse_str(&path)));
}
"ignore" => {
out.debug.ignore = try!(parse_boolean_meta_item(&opt_string_to_str!(value), true, "ignore"));
Expand All @@ -409,7 +409,7 @@ impl Field {
"bound" => try!(parse_bound(&mut out.default.bounds, opt_string_to_str!(value))),
"value" => {
let value = try!(opt_string_to_str!(value).ok_or_else(|| "`value` needs a value".to_string()));
out.default.value = Some(try!(parse_str_to_type(&value)));
out.default.value = Some(try!(parse_str(&value)));
}
}
}
Expand All @@ -425,7 +425,7 @@ impl Field {
"bound" => try!(parse_bound(&mut out.hash.bounds, opt_string_to_str!(value))),
"hash_with" => {
let path = try!(opt_string_to_str!(value).ok_or_else(|| "`hash_with` needs a value".to_string()));
out.hash.hash_with = Some(try!(parse_str_to_type::<syn::Path>(&path)));
out.hash.hash_with = Some(try!(parse_str(&path)));
}
"ignore" => {
out.hash.ignore = try!(parse_boolean_meta_item(&opt_string_to_str!(value), true, "ignore"));
Expand All @@ -438,7 +438,7 @@ impl Field {
"bound" => try!(parse_bound(&mut out.partial_eq.bounds, opt_string_to_str!(value))),
"compare_with" => {
let path = try!(opt_string_to_str!(value).ok_or_else(|| "`compare_with` needs a value".to_string()));
out.partial_eq.compare_with = Some(try!(parse_str_to_type::<syn::Path>(&path)));
out.partial_eq.compare_with = Some(try!(parse_str(&path)));
}
"ignore" => {
out.partial_eq.ignore = try!(parse_boolean_meta_item(&opt_string_to_str!(value), true, "ignore"));
Expand Down Expand Up @@ -643,11 +643,9 @@ fn string_or_err(lit: &syn::Lit) -> Result<String, String> {
}
}

fn parse_str_to_type<T>(value: &str) -> Result<T, String>
fn parse_str<T>(value: &str) -> Result<T, String>
where
T: syn::parse::Parse,
{
proc_macro2::TokenStream::from_str(value)
.map_err(|e| format!("{:?}", e))
.and_then(|stream| syn::parse2::<T>(stream).map_err(|e| e.to_string()))
syn::parse_str::<T>(value).map_err(|e| e.to_string())
}

0 comments on commit f1abbef

Please sign in to comment.