mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-28 01:52:57 +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.
|
||||
It uses *serde* package as a deserialization library.
|
||||
[HttpRequest::extract_path()](../actix_web/struct.HttpRequest.html#method.extract_path)
|
||||
extracts information, the destination type has to implement *serde's *`Deserialize` trait.
|
||||
[Path](../actix_web/struct.Path.html) extracts information, the destination type
|
||||
has to implement *serde's *`Deserialize` trait.
|
||||
|
||||
```rust
|
||||
# extern crate bytes;
|
||||
@ -342,20 +342,20 @@ struct Info {
|
||||
username: String,
|
||||
}
|
||||
|
||||
fn index(mut req: HttpRequest) -> Result<String> {
|
||||
let info: Info = req.extract_path()?; // <- extract path info using serde
|
||||
// extract path info using serde
|
||||
fn index(info: Path<Info>) -> Result<String> {
|
||||
Ok(format!("Welcome {}!", info.username))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let app = Application::new()
|
||||
.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)
|
||||
provides similar functionality for request query parameters.
|
||||
[Query](../actix_web/struct.Query.html) provides similar functionality for
|
||||
request query parameters.
|
||||
|
||||
|
||||
## Generating resource URLs
|
||||
|
@ -130,7 +130,7 @@ impl Actor for Ws {
|
||||
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) {
|
||||
match msg {
|
||||
|
@ -91,7 +91,7 @@ impl<T, S> Path<T, S> {
|
||||
&self.req
|
||||
}
|
||||
|
||||
/// Deconstruct instance into a parts
|
||||
/// Deconstruct instance into parts
|
||||
pub fn into(self) -> (T, HttpRequest<S>) {
|
||||
(self.item, self.req)
|
||||
}
|
||||
@ -179,7 +179,7 @@ impl<T, S> Query<T, S> {
|
||||
&self.req
|
||||
}
|
||||
|
||||
/// Deconstruct instance into a parts
|
||||
/// Deconstruct instance into parts
|
||||
pub fn into(self) -> (T, HttpRequest<S>) {
|
||||
(self.item, self.req)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user