mirror of https://github.com/rwf2/Rocket.git
Don't repeat parsing of path.
This commit is contained in:
parent
1f19b88803
commit
a4f56f1790
|
@ -85,11 +85,12 @@ impl RouteGenerateExt for RouteParams {
|
||||||
// TODO: Add some kind of logging facility in Rocket to get be able to log
|
// TODO: Add some kind of logging facility in Rocket to get be able to log
|
||||||
// an error/debug message if parsing a parameter fails.
|
// an error/debug message if parsing a parameter fails.
|
||||||
fn generate_param_statements(&self, ecx: &ExtCtxt) -> Vec<Stmt> {
|
fn generate_param_statements(&self, ecx: &ExtCtxt) -> Vec<Stmt> {
|
||||||
|
let params: Vec<_> = self.path_params(ecx).collect();
|
||||||
let mut fn_param_statements = vec![];
|
let mut fn_param_statements = vec![];
|
||||||
|
|
||||||
// Retrieve an iterator over the user's path parameters and ensure that
|
// Retrieve an iterator over the user's path parameters and ensure that
|
||||||
// each parameter appears in the function signature.
|
// each parameter appears in the function signature.
|
||||||
for param in self.path_params(ecx) {
|
for param in ¶ms {
|
||||||
if self.annotated_fn.find_input(param.node).is_none() {
|
if self.annotated_fn.find_input(param.node).is_none() {
|
||||||
let fn_span = self.annotated_fn.span();
|
let fn_span = self.annotated_fn.span();
|
||||||
let msg = format!("'{}' is declared as an argument...", param.node);
|
let msg = format!("'{}' is declared as an argument...", param.node);
|
||||||
|
@ -99,7 +100,7 @@ impl RouteGenerateExt for RouteParams {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a function thats checks if an argument was declared in `path`.
|
// Create a function thats checks if an argument was declared in `path`.
|
||||||
let set: HashSet<&str> = self.path_params(ecx).map(|p| p.node).collect();
|
let set: HashSet<&str> = params.iter().map(|p| p.node).collect();
|
||||||
let declared = &|arg: &&Arg| set.contains(&*arg.name().unwrap());
|
let declared = &|arg: &&Arg| set.contains(&*arg.name().unwrap());
|
||||||
|
|
||||||
// These are all of the arguments in the function signature.
|
// These are all of the arguments in the function signature.
|
||||||
|
|
|
@ -43,10 +43,10 @@ impl<'s, 'a, 'c> Iterator for ParamIter<'s, 'a, 'c> {
|
||||||
|
|
||||||
// Check for nonemptiness and that the characters are correct.
|
// Check for nonemptiness and that the characters are correct.
|
||||||
if param.is_empty() {
|
if param.is_empty() {
|
||||||
self.ctxt.span_err(param_span, "Parameter names cannot be empty.");
|
self.ctxt.span_err(param_span, "parameter names cannot be empty");
|
||||||
None
|
None
|
||||||
} else if param.contains(|c: char| !c.is_alphanumeric()) {
|
} else if param.contains(|c: char| !c.is_alphanumeric()) {
|
||||||
self.ctxt.span_err(param_span, "Parameters must be alphanumeric.");
|
self.ctxt.span_err(param_span, "parameters must be alphanumeric");
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.string = &self.string[(end + 1)..];
|
self.string = &self.string[(end + 1)..];
|
||||||
|
|
Loading…
Reference in New Issue