aboutsummaryrefslogtreecommitdiffstats
path: root/validator_derive/src/lit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'validator_derive/src/lit.rs')
-rw-r--r--validator_derive/src/lit.rs38
1 files changed, 11 insertions, 27 deletions
diff --git a/validator_derive/src/lit.rs b/validator_derive/src/lit.rs
index 0753a17..839b62d 100644
--- a/validator_derive/src/lit.rs
+++ b/validator_derive/src/lit.rs
@@ -1,61 +1,45 @@
-use quote::{self, ToTokens};
+use quote;
use syn;
pub fn lit_to_string(lit: &syn::Lit) -> Option<String> {
match *lit {
- syn::Lit::Str(ref s, _) => Some(s.to_string()),
+ syn::Lit::Str(ref s) => Some(s.value()),
_ => None,
}
}
pub fn lit_to_int(lit: &syn::Lit) -> Option<u64> {
match *lit {
- syn::Lit::Int(ref s, _) => Some(*s),
+ syn::Lit::Int(ref s) => Some(s.value()),
// TODO: remove when attr_literals is stable
- syn::Lit::Str(ref s, _) => Some(s.parse::<u64>().unwrap()),
+ syn::Lit::Str(ref s) => Some(s.value().parse::<u64>().unwrap()),
_ => None,
}
}
pub fn lit_to_float(lit: &syn::Lit) -> Option<f64> {
match *lit {
- syn::Lit::Float(ref s, _) => Some(s.parse::<f64>().unwrap()),
- syn::Lit::Int(ref s, _) => Some(*s as f64),
+ syn::Lit::Float(ref s) => Some(s.value()),
+ syn::Lit::Int(ref s) => Some(s.value() as f64),
// TODO: remove when attr_literals is stable
- syn::Lit::Str(ref s, _) => Some(s.parse::<f64>().unwrap()),
+ syn::Lit::Str(ref s) => Some(s.value().parse::<f64>().unwrap()),
_ => None,
}
}
pub fn lit_to_bool(lit: &syn::Lit) -> Option<bool> {
match *lit {
- syn::Lit::Bool(ref s) => Some(*s),
+ syn::Lit::Bool(ref s) => Some(s.value),
// TODO: remove when attr_literals is stable
- syn::Lit::Str(ref s, _) => if s == "true" { Some(true) } else { Some(false) },
+ syn::Lit::Str(ref s) => if s.value() == "true" { Some(true) } else { Some(false) },
_ => None,
}
}
pub fn option_u64_to_tokens(opt: Option<u64>) -> quote::Tokens {
- let mut tokens = quote::Tokens::new();
- tokens.append("::");
- tokens.append("std");
- tokens.append("::");
- tokens.append("option");
- tokens.append("::");
- tokens.append("Option");
- tokens.append("::");
match opt {
- Some(ref t) => {
- tokens.append("Some");
- tokens.append("(");
- t.to_tokens(&mut tokens);
- tokens.append(")");
- }
- None => {
- tokens.append("None");
- }
+ Some(ref t) => quote!(::std::option::Option::Some(#t)),
+ None => quote!(::std::option::Option::None)
}
- tokens
}