Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. //.. forms.rs
  2. #[derive(FromForm)]
  3. pub struct UpdatePostForm<'a> {
  4. pub id: i32,
  5. pub title: &'a str,
  6. pub content: &'a str,
  7. }
  8.  
  9. // mod.rs
  10. // Need to explicitly annotate lifetimes?
  11. #[post("/update", data = "<form>")]
  12. fn update(user: AuthenticatedUser, form: Form<UpdatePostForm>, conn: DbConn) -> Result<Redirect, Flash<Redirect>> {
  13. use super::schema::posts::dsl::*;
  14.  
  15. let form = form.get();
  16. let update_post = UpdatePost {
  17. user_id: None,
  18. title: form.title,
  19. content: form.content,
  20. published: false,
  21. };
  22.  
  23. diesel::update(posts.find(form.id))
  24. .set(&update_post)
  25. .get_result::<Post>(&*conn)
  26. .expect("Error updating Post");
  27.  
  28. Ok(Redirect::to("/"))
  29. }
  30.  
  31. // ERRORS
  32. 109 | / fn update(user: AuthenticatedUser, form: Form<UpdatePostForm>, conn: DbConn) -> Result<Redirect, Flash<Redirect>>{
  33. 110 | | use super::schema::posts::dsl::*;
  34. 111 | |
  35. 112 | | let form = form.get();
  36. ... |
  37. 132 | | Ok(Redirect::to("/"))
  38. 133 | | }
  39. | |_^
  40. |
  41. note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the function body at 109:1...
  42. --> src/posts/mod.rs:109:1
  43. |
  44. 109 | / fn update(user: AuthenticatedUser, form: Form<UpdatePostForm>, conn: DbConn) -> Result<Redirect, Flash<Redirect>>{
  45. 110 | | use super::schema::posts::dsl::*;
  46. 111 | |
  47. 112 | | let form = form.get();
  48. ... |
  49. 132 | | Ok(Redirect::to("/"))
  50. 133 | | }
  51. | |_^
  52. note: ...so that types are compatible (expected rocket::request::FromForm<'_>, found rocket::request::FromForm<'_>)
  53. --> src/posts/mod.rs:109:1
  54. |
  55. 109 | / fn update(user: AuthenticatedUser, form: Form<UpdatePostForm>, conn: DbConn) -> Result<Redirect, Flash<Redirect>>{
  56. 110 | | use super::schema::posts::dsl::*;
  57. 111 | |
  58. 112 | | let form = form.get();
  59. ... |
  60. 132 | | Ok(Redirect::to("/"))
  61. 133 | | }
  62. | |_^
  63. note: but, the lifetime must be valid for the anonymous lifetime #2 defined on the function body at 109:1...
  64. --> src/posts/mod.rs:109:1
  65. |
  66. 109 | / fn update(user: AuthenticatedUser, form: Form<UpdatePostForm>, conn: DbConn) -> Result<Redirect, Flash<Redirect>>{
  67. 110 | | use super::schema::posts::dsl::*;
  68. 111 | |
  69. 112 | | let form = form.get();
  70. ... |
  71. 132 | | Ok(Redirect::to("/"))
  72. 133 | | }
  73. | |_^
  74. note: ...so that types are compatible (expected rocket::request::FromForm<'_>, found rocket::request::FromForm<'_>)
  75. --> src/posts/mod.rs:109:1
  76. |
  77. 109 | / fn update(user: AuthenticatedUser, form: Form<UpdatePostForm>, conn: DbConn) -> Result<Redirect, Flash<Redirect>>{
  78. 110 | | use super::schema::posts::dsl::*;
  79. 111 | |
  80. 112 | | let form = form.get();
  81. ... |
  82. 132 | | Ok(Redirect::to("/"))
  83. 133 | | }
  84. | |_^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement