Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use chrono::{Local, NaiveDateTime}; // 0.4.6use std::Debug;
- pub struct User {
- pub email: String,
- pub password: String,
- pub created_at: NaiveDateTime, // only NaiveDateTime works here due to diesel limitations
- }
- impl User {
- pub fn with_details(email: String, password: String) -> Self {
- User {
- email,
- password,
- created_at: Local::now().naive_local(),
- }
- }
- }
- #[derive(Debug)]
- pub struct SlimUser {
- pub email: String,
- pub created_at: NaiveDateTime
- }
- impl From<User> for SlimUser {
- fn from(user: User) -> Self {
- SlimUser { email: user.email, created_at: user.created_at }
- }
- }
- fn main(){
- let user = User::with_details("email@gmail.com".to_owned(), "password".to_owned());
- println!("{:?}", SlimUser::from(user));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement