depo_api/request/
finish_recovery.rs

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