DEV Community


Discussion on: A Web App in Rust - 08 Submitting a New Post

romanlevin profile image
Roman Levin

This line admittedly does bother me as we are doing a clone to pass the data. I did not figure out what the borrowing rules here should be.

Pretty sure the answer here is to actually do what the method name implies, make a NewPost from the PostForm:

pub fn from_post_form(form: PostForm, id: i32) {


let new_post = NewPost::from_post_form(data.into_inner(),;
Enter fullscreen mode Exit fullscreen mode

Since you don't need the Form<PostForm>, there's no need to clone anything, just pass ownership of the entire object.

krowemoh profile image
Nivethan Author

Ah! This is good, feels much better, because we don't use data later on we can give ownership away. I also should have read the WebForm doc, into_inner() really simplified things.

Thank you! I'll add a note to take a look at this comment.