use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct FnResult { error: Option, result: Option, } impl FnResult { pub fn fail(message: impl Into) -> Self { FnResult { result: None, error: Some(message.into()), } } pub fn success(result: impl Into) -> Self { FnResult { result: Some(result.into()), error: None, } } pub fn to_json(&self) -> String { serde_json::to_string(&self).expect("JSResult to json error") } }