The values line is one line I have no idea about. Without the * there is an error saying the Insertable trait isn't set up properly on the NewUser struct but I don't know what is wrong with it.
data has the type of web::Form<NewUser>. The * there can deference it into NewUser because we have impl<T> Deref for Form<T> (Doc). And the NewUser struct is the type implements Insertable trait required by the values() function.
& to me implies address and * means get the value at the address, would that be a valid way of thinking that data's address contains the NewUser struct? This would mean web::Form is really the address of some struct T.
Or does Deref mean something else in this context.
The additional & is necessary, because as rustc tells us, it would mean moving the NewUser out, but that's impossible because data still owns it, so borrowing (&) the dereferenced NewUser allows us to send it to values without violating ownership rules.
An alternative would be to do values(data.into_inner()) which moves the NewUser out of the web::Form by consuming it.
By the way, Nivethan, this is a wonderful series. Thank you so much for the effort you put in!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
datahas the type ofweb::Form<NewUser>. The*there can deference it intoNewUserbecause we haveimpl<T> Deref for Form<T>(Doc). And theNewUserstruct is the type implementsInsertabletrait required by thevalues()function.Ah! Thank you that makes sense.
& to me implies address and * means get the value at the address, would that be a valid way of thinking that data's address contains the NewUser struct? This would mean web::Form is really the address of some struct T.
Or does Deref mean something else in this context.
web::FormwrapsNewUser, but it isn't a pointer to aNewUser.Derefforweb::Formis very simple:The additional
&is necessary, because asrustctells us, it would mean moving theNewUserout, but that's impossible becausedatastill owns it, so borrowing (&) the dereferencedNewUserallows us to send it tovalueswithout violating ownership rules.An alternative would be to do
values(data.into_inner())which moves theNewUserout of theweb::Formby consuming it.By the way, Nivethan, this is a wonderful series. Thank you so much for the effort you put in!