1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//!Enable to parse request/response JSONs into the following object structs.
use serde::{Deserialize, Serialize};

///Needs to implement `serde::Deserialize` trait in order to use it as proper handler extractor
#[derive(Deserialize)]
pub struct RequestJson {
    pub data: String,
}

///Needs to implement `serde::Serialize` trait in order to use it as proper json Response object.
#[derive(Serialize)]
pub struct ResponseJson {
    pub output: String,
}

///Implements app state struct.
#[derive(Debug, Clone)]
pub struct AppState {
    counter: u32,
}

///Implement getters, setters and constructor for `AppState`.
impl AppState {
    pub fn new() -> Self {
        Self { counter: 0 }
    }
    pub fn get_counter(&self) -> &u32 {
        &self.counter
    }
    pub fn increment(&mut self) {
        self.counter += 1;
    }
}