mirror of https://github.com/rwf2/Rocket.git
Prefix 'uri!' format args to allow ignored parameters.
This commit is contained in:
parent
3413129296
commit
648eb1a5eb
|
@ -128,6 +128,10 @@ pub fn uri_internal(
|
|||
// Building <$T as ::rocket::http::uri::FromUriParam<_>>::from_uri_param($e).
|
||||
for (i, &(mut ident, ref ty)) in internal.fn_args.iter().enumerate() {
|
||||
let (span, mut expr) = (exprs[i].span, exprs[i].clone());
|
||||
|
||||
// Format argument names cannot begin with `_`, but a function parameter
|
||||
// might, so we prefix each parameter with the letters `fmt`.
|
||||
ident.name = Symbol::intern(&format!("fmt{}", ident.name));
|
||||
ident.span = span;
|
||||
|
||||
// path for call: <T as FromUriParam<_>>::from_uri_param
|
||||
|
|
|
@ -255,7 +255,7 @@ impl InternalUriParams {
|
|||
|
||||
pub fn uri_fmt_string(&self) -> String {
|
||||
self.uri.node
|
||||
.replace('<', "{")
|
||||
.replace('<', "{fmt")
|
||||
.replace("..>", "}")
|
||||
.replace('>', "}")
|
||||
}
|
||||
|
|
|
@ -50,6 +50,9 @@ fn simple2(id: i32, name: String) -> &'static str { "" }
|
|||
#[post("/<id>/<name>")]
|
||||
fn simple2_flipped(name: String, id: i32) -> &'static str { "" }
|
||||
|
||||
#[post("/<used>/<_unused>")]
|
||||
fn unused_param(used: i32, _unused: i32) -> &'static str { "" }
|
||||
|
||||
#[post("/<id>")]
|
||||
fn guard_1(cookies: Cookies, id: i32) -> &'static str { "" }
|
||||
|
||||
|
@ -90,6 +93,7 @@ fn check_simple_unnamed() {
|
|||
assert_uri_eq! {
|
||||
uri!(simple: 100) => "/100",
|
||||
uri!(simple: -23) => "/-23",
|
||||
uri!(unused_param: 1, 2) => "/1/2",
|
||||
}
|
||||
|
||||
// The "flipped" test ensures that the order of parameters depends on the
|
||||
|
@ -118,6 +122,7 @@ fn check_simple_named() {
|
|||
assert_uri_eq! {
|
||||
uri!(simple: id = 100) => "/100",
|
||||
uri!(simple: id = -23) => "/-23",
|
||||
uri!(unused_param: used = 1, _unused = 2) => "/1/2",
|
||||
}
|
||||
|
||||
assert_uri_eq! {
|
||||
|
|
Loading…
Reference in New Issue