//! Player information use std::convert::TryFrom; use std::error::Error; use chrono::{DateTime, Utc}; use rusqlite::{types::FromSql, Row}; use serde_derive::{Deserialize, Serialize}; use crate::id::Id; /// Player information #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Player { /// Unique identifier pub id: Id, /// Player name pub name: String, /// Player's password (this needs to be properly salted and hashed but isn't) pub password: String, /// Creation DateTime pub created: DateTime, /// Player's location pub location: Id, } impl<'a> TryFrom<&Row<'a>> for Player { type Error = Box; fn try_from(row: &Row) -> Result { Ok(Self { id: try_log!(row.get("id"), "id"), name: try_log!(row.get("name"), "name"), password: try_log!(row.get("password"), "password"), created: try_log!(row.get("created"), "created"), location: try_log!(row.get("location"), "location"), }) } }