depo_api/request/
delete_account.rs

1use bc_envelope::prelude::*;
2use anyhow::{ Error, Result };
3
4use crate::{ DELETE_ACCOUNT_FUNCTION, util::FlankedFunction };
5
6//
7// Request
8//
9
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct DeleteAccount();
12
13impl DeleteAccount {
14    pub fn new() -> Self {
15        Self()
16    }
17}
18
19impl Default for DeleteAccount {
20    fn default() -> Self {
21        Self::new()
22    }
23}
24
25impl From<DeleteAccount> for Expression {
26    fn from(_: DeleteAccount) -> Self {
27        Expression::new(DELETE_ACCOUNT_FUNCTION)
28    }
29}
30
31impl TryFrom<Expression> for DeleteAccount {
32    type Error = Error;
33
34    fn try_from(_: Expression) -> Result<Self> {
35        Ok(Self::new())
36    }
37}
38
39impl std::fmt::Display for DeleteAccount {
40    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41        f.write_fmt(format_args!("{}", "deleteAccount".flanked_function()))
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use indoc::indoc;
48
49    use super::*;
50
51    #[test]
52    fn test_request() {
53        bc_envelope::register_tags();
54
55        let request = DeleteAccount::new();
56        let expression: Expression = request.clone().into();
57        let request_envelope = expression.to_envelope();
58
59        // println!("{}", request_envelope.format());
60        #[rustfmt::skip]
61        assert_eq!(request_envelope.format(), indoc! {r#"
62            «"deleteAccount"»
63        "#}.trim());
64        let decoded_expression = Expression::try_from(request_envelope).unwrap();
65        let decoded = DeleteAccount::try_from(decoded_expression).unwrap();
66        assert_eq!(request, decoded);
67    }
68}