ruwebframe 0.1.8

a simple webframe for rust actix-web, based on rudi and rbatis.
Documentation
use serde::de::DeserializeOwned;
use serde::Serialize;
use crate::rubase::ruentity::json_serial::JsonSerializable;

pub trait BaseEntity {
    fn if_single(&self) -> bool { false }
    fn init(&mut self) {}
    fn shutdown(&mut self) {}
    fn auto_init(&self) -> bool { false }
    fn to_json(&self) -> Result<String, serde_json::Error>
    where
        Self: Serialize,
    {
        serde_json::to_string_pretty(self) // 直接用 serde,省去 json_utils 包装
    }

    fn from_json(&self, from: String) -> Result<Self, serde_json::Error>
    where
        Self: Serialize + DeserializeOwned,
    {
        serde_json::from_str(from.as_str())
    }
}

//多实例

// 使用 macro_rules! 定义派生宏
// 注意:语法为 derive() (struct ...)
// macro_rules! TraitEntity {
//     // derive() 规则处理结构体
//     derive() (struct $name:ident $($rest:tt)*) => {
//     impl TraitEntity for $name {
//     fn entity_name() -> &'static str {
//     stringify!($name)
//     }
//     }
//     };
//     // 可以添加更多规则以支持 enum、union 等
// }