mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-30 18:44:35 +01:00
update guide
This commit is contained in:
parent
7d6deab9fb
commit
32052c2750
@ -327,8 +327,8 @@ List of `FromParam` implementations can be found in
|
|||||||
|
|
||||||
Actix provides functionality for type safe request path information extraction.
|
Actix provides functionality for type safe request path information extraction.
|
||||||
It uses *serde* package as a deserialization library.
|
It uses *serde* package as a deserialization library.
|
||||||
[HttpRequest::extract_path()](../actix_web/struct.HttpRequest.html#method.extract_path)
|
[Path](../actix_web/struct.Path.html) extracts information, the destination type
|
||||||
extracts information, the destination type has to implement *serde's *`Deserialize` trait.
|
has to implement *serde's *`Deserialize` trait.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
# extern crate bytes;
|
# extern crate bytes;
|
||||||
@ -342,20 +342,20 @@ struct Info {
|
|||||||
username: String,
|
username: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index(mut req: HttpRequest) -> Result<String> {
|
// extract path info using serde
|
||||||
let info: Info = req.extract_path()?; // <- extract path info using serde
|
fn index(info: Path<Info>) -> Result<String> {
|
||||||
Ok(format!("Welcome {}!", info.username))
|
Ok(format!("Welcome {}!", info.username))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let app = Application::new()
|
let app = Application::new()
|
||||||
.resource("/{username}/index.html", // <- define path parameters
|
.resource("/{username}/index.html", // <- define path parameters
|
||||||
|r| r.method(Method::GET).f(index));
|
|r| r.method(Method::GET).with(index));
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
[HttpRequest::extract_query()](../actix_web/struct.HttpRequest.html#method.extract_query)
|
[Query](../actix_web/struct.Query.html) provides similar functionality for
|
||||||
provides similar functionality for request query parameters.
|
request query parameters.
|
||||||
|
|
||||||
|
|
||||||
## Generating resource URLs
|
## Generating resource URLs
|
||||||
|
@ -130,7 +130,7 @@ impl Actor for Ws {
|
|||||||
type Context = ws::WebsocketContext<Self>;
|
type Context = ws::WebsocketContext<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StreamHandler<ws::Message, ws::WsError> for Ws {
|
impl StreamHandler<ws::Message, ws::ProtocolError> for Ws {
|
||||||
|
|
||||||
fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
|
fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
|
||||||
match msg {
|
match msg {
|
||||||
|
@ -91,7 +91,7 @@ impl<T, S> Path<T, S> {
|
|||||||
&self.req
|
&self.req
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deconstruct instance into a parts
|
/// Deconstruct instance into parts
|
||||||
pub fn into(self) -> (T, HttpRequest<S>) {
|
pub fn into(self) -> (T, HttpRequest<S>) {
|
||||||
(self.item, self.req)
|
(self.item, self.req)
|
||||||
}
|
}
|
||||||
@ -179,7 +179,7 @@ impl<T, S> Query<T, S> {
|
|||||||
&self.req
|
&self.req
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deconstruct instance into a parts
|
/// Deconstruct instance into parts
|
||||||
pub fn into(self) -> (T, HttpRequest<S>) {
|
pub fn into(self) -> (T, HttpRequest<S>) {
|
||||||
(self.item, self.req)
|
(self.item, self.req)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user