From ee5e8694425423b41c5afc975e27c867ac42fbce Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Sun, 4 Feb 2024 17:43:17 -0500 Subject: [PATCH] Implement User conversions --- src/models.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/models.rs b/src/models.rs index d93bc97..fec0ab6 100644 --- a/src/models.rs +++ b/src/models.rs @@ -44,6 +44,17 @@ pub struct NewUser { pub password: String, } +/// Convert a User into a NewUser, omitting the id and created_at fields +impl From for NewUser { + fn from(user: User) -> NewUser { + NewUser { + username: user.username, + email: user.email, + password: user.password, + } + } +} + /// Model for a "Public User", used for returning user data to the client /// This model omits the password field, so that the hashed password is not sent to the client #[cfg_attr(feature = "ssr", derive(Queryable, Selectable))] @@ -60,3 +71,15 @@ pub struct PublicUser { /// The time the user was created pub created_at: SystemTime, } + +/// Convert a User into a PublicUser, omitting the password field +impl From for PublicUser { + fn from(user: User) -> PublicUser { + PublicUser { + id: user.id, + username: user.username, + email: user.email, + created_at: user.created_at, + } + } +}