use crate::rubase::rutils::jsonutils;
use crate::rubase::BaseEntity;
use crate::rulog;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fmt::Debug;
use crate::rubase::getself::GetSelf;
#[derive(Serialize, Default, Deserialize, Debug, Clone)]
pub struct Person {
pub id: i64,
pub name: String,
pub age: u16,
pub active: bool,
}
impl BaseEntity for Person {}
impl GetSelf for Person {}
impl fmt::Display for Person {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let result = jsonutils::struct2json(&self);
match result {
Ok(data) => {
println!("成功: {:?}", data);
crate::rulog::rulog::info(data.as_str());
Ok(())
}
Err(e) => {
eprintln!("JSON 解析失败: {}", e);
Err(fmt::Error) }
}
}
}
impl Person {
pub fn log(&self) -> &Person {
rulog::info(self.to_json().as_str());
self
}
pub fn new() -> Person {
Person::default()
}
pub fn new_as(id: i64, name: String, age: u16, active: bool) -> Person {
Person {
id,
name,
age,
active,
}
}
}