Advertisement
Guest User

Untitled

a guest
Mar 8th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.76 KB | None | 0 0
  1. use chrono::{Local, NaiveDateTime}; // 0.4.6use std::Debug;
  2.  
  3. pub struct User {
  4.     pub email: String,
  5.     pub password: String,
  6.     pub created_at: NaiveDateTime, // only NaiveDateTime works here due to diesel limitations
  7. }
  8.  
  9. impl User {
  10.     pub fn with_details(email: String, password: String) -> Self {
  11.         User {
  12.             email,
  13.             password,
  14.             created_at: Local::now().naive_local(),
  15.         }
  16.     }
  17. }
  18.  
  19. #[derive(Debug)]
  20. pub struct SlimUser {
  21.     pub email: String,
  22.     pub created_at: NaiveDateTime
  23. }
  24.  
  25. impl From<User> for SlimUser {
  26.     fn from(user: User) -> Self {
  27.         SlimUser { email: user.email, created_at: user.created_at }
  28.     }
  29. }
  30.  
  31. fn main(){
  32.     let user = User::with_details("email@gmail.com".to_owned(), "password".to_owned());
  33.     println!("{:?}", SlimUser::from(user));
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement