model_macro/
lib.rs

1use bevy_reflect::{reflect_trait, Reflect};
2use std::any::Any;
3
4pub trait ModelTrait: Any + Send + Sync + Sized + Reflect + Clone {
5    fn clear_model(&self) -> Self
6    where
7        Self: Sized;
8    fn set_field(
9        &mut self,
10        value: String,
11        field_name: &str,
12    ) -> Result<&Self, Box<dyn std::error::Error + Sync + Send>>
13    where
14        Self: Sized;
15    fn new() -> Self
16    where
17        Self: Sized;
18    fn clone_model(&self) -> Self
19    where
20        Self: Sized;
21    fn get_field_str(&self, field_name: &str) -> Option<String>;
22}
23
24#[reflect_trait]
25pub trait Validator {
26    fn checkout(&self) -> std::result::Result<usize, Box<dyn std::error::Error + Send + Sync>>;
27}
28
29pub mod err {
30    use std::fmt::Display;
31
32    use serde::{Deserialize, Serialize};
33
34    #[derive(Debug, Clone, Deserialize, Serialize)]
35    pub struct ResponseError {
36        pub biz_res: String,
37        pub message: Option<String>,
38    }
39
40    impl Display for ResponseError {
41        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42            write!(f, "response error in app",)
43        }
44    }
45
46    impl std::error::Error for ResponseError {
47        fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
48            Some(self)
49        }
50
51        fn description(&self) -> &str {
52            "description() is deprecated; use Display"
53        }
54
55        fn cause(&self) -> Option<&dyn std::error::Error> {
56            self.source()
57        }
58    }
59}