// this struct for http post user info.
struct RequestUserPayload{
first_name:String,
last_name:String,
age:u8,
email:String,
// and more details
}
// this struct for database table mapping
struct User{
id:u32,
first_name:String,
last_name:String,
age:u8,
email:String,
// same as RequestUserPayload field
create_at: NaiveDateTime,
update_at: NaiveDateTime
}
The User struct include RequestUserPayload. So, I think there is an easy way to convert it.
Maybe, it could use memory copy or pointer? I dont know.
You could try to do something fancy with procedural macros or unsafe, but that'll just make it hard to understand what is going on and probably be slower at runtime. The optimiser will need to peel away any layers of abstraction you add, and unsafe code can sometimes hurt performance because the optimiser can't make assumptions that might minimise work.