Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //.. forms.rs
- #[derive(FromForm)]
- pub struct UpdatePostForm<'a> {
- pub id: i32,
- pub title: &'a str,
- pub content: &'a str,
- }
- // mod.rs
- // Need to explicitly annotate lifetimes?
- #[post("/update", data = "<form>")]
- fn update(user: AuthenticatedUser, form: Form<UpdatePostForm>, conn: DbConn) -> Result<Redirect, Flash<Redirect>> {
- use super::schema::posts::dsl::*;
- let form = form.get();
- let update_post = UpdatePost {
- user_id: None,
- title: form.title,
- content: form.content,
- published: false,
- };
- diesel::update(posts.find(form.id))
- .set(&update_post)
- .get_result::<Post>(&*conn)
- .expect("Error updating Post");
- Ok(Redirect::to("/"))
- }
- // ERRORS
- 109 | / fn update(user: AuthenticatedUser, form: Form<UpdatePostForm>, conn: DbConn) -> Result<Redirect, Flash<Redirect>>{
- 110 | | use super::schema::posts::dsl::*;
- 111 | |
- 112 | | let form = form.get();
- ... |
- 132 | | Ok(Redirect::to("/"))
- 133 | | }
- | |_^
- |
- note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the function body at 109:1...
- --> src/posts/mod.rs:109:1
- |
- 109 | / fn update(user: AuthenticatedUser, form: Form<UpdatePostForm>, conn: DbConn) -> Result<Redirect, Flash<Redirect>>{
- 110 | | use super::schema::posts::dsl::*;
- 111 | |
- 112 | | let form = form.get();
- ... |
- 132 | | Ok(Redirect::to("/"))
- 133 | | }
- | |_^
- note: ...so that types are compatible (expected rocket::request::FromForm<'_>, found rocket::request::FromForm<'_>)
- --> src/posts/mod.rs:109:1
- |
- 109 | / fn update(user: AuthenticatedUser, form: Form<UpdatePostForm>, conn: DbConn) -> Result<Redirect, Flash<Redirect>>{
- 110 | | use super::schema::posts::dsl::*;
- 111 | |
- 112 | | let form = form.get();
- ... |
- 132 | | Ok(Redirect::to("/"))
- 133 | | }
- | |_^
- note: but, the lifetime must be valid for the anonymous lifetime #2 defined on the function body at 109:1...
- --> src/posts/mod.rs:109:1
- |
- 109 | / fn update(user: AuthenticatedUser, form: Form<UpdatePostForm>, conn: DbConn) -> Result<Redirect, Flash<Redirect>>{
- 110 | | use super::schema::posts::dsl::*;
- 111 | |
- 112 | | let form = form.get();
- ... |
- 132 | | Ok(Redirect::to("/"))
- 133 | | }
- | |_^
- note: ...so that types are compatible (expected rocket::request::FromForm<'_>, found rocket::request::FromForm<'_>)
- --> src/posts/mod.rs:109:1
- |
- 109 | / fn update(user: AuthenticatedUser, form: Form<UpdatePostForm>, conn: DbConn) -> Result<Redirect, Flash<Redirect>>{
- 110 | | use super::schema::posts::dsl::*;
- 111 | |
- 112 | | let form = form.get();
- ... |
- 132 | | Ok(Redirect::to("/"))
- 133 | | }
- | |_^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement