mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-30 21:32:02 +00:00
Fix database usage code in state guide: '&*conn'.
This commit is contained in:
parent
df1ca03458
commit
6279039361
@ -242,7 +242,7 @@ single connection from the managed connection pool. We create a new type,
|
|||||||
`DbConn`, that wraps an `r2d2` pooled connection. We then implement
|
`DbConn`, that wraps an `r2d2` pooled connection. We then implement
|
||||||
`FromRequest` for `DbConn` so that we can use it as a request guard. Finally, we
|
`FromRequest` for `DbConn` so that we can use it as a request guard. Finally, we
|
||||||
implement `Deref` with a target of `SqliteConnection` so that we can
|
implement `Deref` with a target of `SqliteConnection` so that we can
|
||||||
transparently use an `&DbConn` as an `&SqliteConnection`.
|
transparently use an `&*DbConn` as an `&SqliteConnection`.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
@ -289,7 +289,7 @@ array of some `Task` structures that are fetched from a database:
|
|||||||
#[get("/tasks")]
|
#[get("/tasks")]
|
||||||
fn get_tasks(conn: DbConn) -> QueryResult<Json<Vec<Task>>> {
|
fn get_tasks(conn: DbConn) -> QueryResult<Json<Vec<Task>>> {
|
||||||
all_tasks.order(tasks::id.desc())
|
all_tasks.order(tasks::id.desc())
|
||||||
.load::<Task>(&conn)
|
.load::<Task>(&*conn)
|
||||||
.map(|tasks| Json(tasks))
|
.map(|tasks| Json(tasks))
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user