Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Serialize, Deserialize, Insertable)]
- #[table_name="users"]
- pub struct NewUser {
- pub name: String,
- pub username: String,
- pub email: String,
- #[serde(rename(deserialize = "password"))]
- #[serde(deserialize_with = "hash_user_password")]
- pub hashed_password: String
- }
- fn hash_user_password<D>(deserializer: D) -> Result<String, D::Error>
- where D: Deserializer
- {
- let password: String = Deserialize::deserialize(deserializer)?;
- hash(&password, DEFAULT_COST)
- .map_err(de::Error::custom)
- .map(|hashed_password|hashed_password)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement