openlegends_api/user/register/
response.rs1pub mod data;
2pub mod error;
3
4pub use data::Data;
5pub use error::Error;
6
7use serde::{Deserialize, Serialize};
8
9#[derive(Serialize, Deserialize, Debug)]
10pub struct Response {
11 success: bool,
12 message: String,
13}
14
15impl Response {
16 pub fn build(success: bool, message: String) -> Self {
17 Self { success, message }
18 }
19
20 pub fn from_json(json: &str) -> Result<Self, Error> {
21 match serde_json::from_str::<Response>(json) {
22 Ok(data) => Ok(Self {
23 success: data.success,
24 message: data.message,
25 }),
26 Err(e) => Err(Error::Json(e)),
27 }
28 }
29
30 pub fn to_json(&self) -> Result<String, Error> {
31 match serde_json::to_string(&self) {
32 Ok(json) => Ok(json),
33 Err(e) => Err(Error::Json(e)),
34 }
35 }
36
37 pub fn success(&self) -> bool {
38 self.success
39 }
40
41 pub fn message(&self) -> &str {
42 &self.message
43 }
44}