mirror of https://github.com/rwf2/Rocket.git
Don't use &str where RawStr is now preferred.
This commit is contained in:
parent
da1f6264e4
commit
2e54a1f74d
|
@ -16,7 +16,7 @@ expressibility, and speed. Here's an example of a complete Rocket application:
|
|||
extern crate rocket;
|
||||
|
||||
#[get("/<name>/<age>")]
|
||||
fn hello(name: &str, age: u8) -> String {
|
||||
fn hello(name: String, age: u8) -> String {
|
||||
format!("Hello, {} year old named {}!", age, name)
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
fn get() -> &'static str { "hi" }
|
||||
|
||||
#[get("")] //~ ERROR absolute
|
||||
fn get1(name: &str) -> &'static str { "hi" }
|
||||
fn get1(id: usize) -> &'static str { "hi" }
|
||||
|
||||
#[get("a/b/c")] //~ ERROR absolute
|
||||
fn get2(name: &str) -> &'static str { "hi" }
|
||||
fn get2(id: usize) -> &'static str { "hi" }
|
||||
|
||||
fn main() { }
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
extern crate rocket;
|
||||
|
||||
#[get("/")]
|
||||
fn get(_: &str) -> &'static str { "hi" } //~ ERROR argument
|
||||
fn get(_: usize) -> &'static str { "hi" } //~ ERROR argument
|
||||
|
||||
fn main() { }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#![plugin(rocket_codegen)]
|
||||
|
||||
#[get("/<name>")] //~ ERROR 'name' is declared
|
||||
fn get(other: &str) -> &'static str { "hi" } //~ ERROR isn't in the function
|
||||
fn get(other: usize) -> &'static str { "hi" } //~ ERROR isn't in the function
|
||||
|
||||
#[get("/a?<r>")] //~ ERROR 'r' is declared
|
||||
fn get1() -> &'static str { "hi" } //~ ERROR isn't in the function
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
#[get("/><")] //~ ERROR malformed
|
||||
fn get() -> &'static str { "hi" }
|
||||
|
||||
#[get("/<name><")] //~ ERROR malformed
|
||||
fn get1(name: &str) -> &'static str { "hi" }
|
||||
#[get("/<id><")] //~ ERROR malformed
|
||||
fn get1(id: usize) -> &'static str { "hi" }
|
||||
|
||||
#[get("/<<<<name><")] //~ ERROR malformed
|
||||
fn get2(name: &str) -> &'static str { "hi" }
|
||||
#[get("/<<<<id><")] //~ ERROR malformed
|
||||
fn get2(id: usize) -> &'static str { "hi" }
|
||||
|
||||
#[get("/<!>")] //~ ERROR identifiers
|
||||
fn get3() -> &'static str { "hi" }
|
||||
|
|
|
@ -33,6 +33,7 @@ smallvec = { git = "https://github.com/SergioBenitez/rust-smallvec" }
|
|||
pear = "0.0.8"
|
||||
pear_codegen = "0.0.8"
|
||||
rustls = { version = "0.5.8", optional = true }
|
||||
cookie = { version = "0.7.4", features = ["percent-encode", "secure"] }
|
||||
|
||||
[dependencies.hyper-rustls]
|
||||
git = "https://github.com/SergioBenitez/hyper-rustls"
|
||||
|
@ -40,10 +41,6 @@ default-features = false
|
|||
features = ["server"]
|
||||
optional = true
|
||||
|
||||
[dependencies.cookie]
|
||||
version = "0.7.4"
|
||||
features = ["percent-encode", "secure"]
|
||||
|
||||
[dev-dependencies]
|
||||
lazy_static = "0.2"
|
||||
rocket_codegen = { version = "0.2.4", path = "../codegen" }
|
||||
|
|
|
@ -181,17 +181,20 @@ impl<T, E> FormResult<T, E> {
|
|||
|
||||
impl<'f, T: FromForm<'f> + 'f> Form<'f, T> {
|
||||
/// Immutably borrow the parsed type.
|
||||
#[inline(always)]
|
||||
pub fn get(&'f self) -> &'f T {
|
||||
&self.object
|
||||
}
|
||||
|
||||
/// Mutably borrow the parsed type.
|
||||
#[inline(always)]
|
||||
pub fn get_mut(&'f mut self) -> &'f mut T {
|
||||
&mut self.object
|
||||
}
|
||||
|
||||
/// Returns the raw form string that was used to parse the encapsulated
|
||||
/// object.
|
||||
#[inline(always)]
|
||||
pub fn raw_form_string(&self) -> &str {
|
||||
&self.form_string
|
||||
}
|
||||
|
@ -240,6 +243,7 @@ impl<'f, T: FromForm<'f> + 'f> Form<'f, T> {
|
|||
|
||||
impl<'f, T: FromForm<'f> + 'static> Form<'f, T> {
|
||||
/// Consume this object and move out the parsed object.
|
||||
#[inline(always)]
|
||||
pub fn into_inner(self) -> T {
|
||||
self.object
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ impl<'r> Responder<'r> for &'r str {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns a response with Content-Type `text/html` and a fixed-size body
|
||||
/// Returns a response with Content-Type `text/plain` and a fixed-size body
|
||||
/// containing the string `self`. Always returns `Ok`.
|
||||
impl Responder<'static> for String {
|
||||
fn respond(self) -> Result<Response<'static>, Status> {
|
||||
|
|
|
@ -292,7 +292,7 @@ mod test {
|
|||
assert!(routed_to.len() == expected.len());
|
||||
for (got, expected) in routed_to.iter().zip(expected.iter()) {
|
||||
assert_eq!(got.rank, expected.0);
|
||||
assert_eq!(got.path.as_str() as &str, expected.1);
|
||||
assert_eq!(got.path.as_str(), expected.1);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -361,7 +361,7 @@ mod test {
|
|||
let expected = &[$($want),+];
|
||||
assert!(routed_to.len() == expected.len());
|
||||
for (got, expected) in routed_to.iter().zip(expected.iter()) {
|
||||
assert_eq!(got.path.as_str() as &str, expected as &str);
|
||||
assert_eq!(got.path.as_str(), expected as &str);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue