openlegends_api/user/register/
request.rs

1pub mod data;
2pub mod error;
3pub mod header;
4
5pub use data::Data;
6pub use error::Error;
7pub use header::HEADER;
8
9pub struct Request {
10    data: Data,
11    header: String,
12}
13
14impl Request {
15    pub fn build(username: String, password: String) -> Result<Self, Error> {
16        Ok(Self {
17            data: match Data::build(username, password) {
18                Ok(data) => data,
19                Err(e) => return Err(Error::Data(e)),
20            },
21            header: HEADER.to_string(),
22        })
23    }
24
25    pub fn to_string(&self) -> Result<String, Error> {
26        Ok(format!(
27            "{}\r\n{}",
28            self.header,
29            match self.data.to_json() {
30                Ok(json) => json,
31                Err(e) => return Err(Error::Data(e)),
32            }
33        ))
34    }
35}