example_webserver_rs/
structs.rs

1//!Enable to parse request/response JSONs into the following object structs.
2use serde::{Deserialize, Serialize};
3
4///Needs to implement `serde::Deserialize` trait in order to use it as proper handler extractor
5#[derive(Deserialize)]
6pub struct RequestJson {
7    pub data: String,
8}
9
10///Needs to implement `serde::Serialize` trait in order to use it as proper json Response object.
11#[derive(Serialize)]
12pub struct ResponseJson {
13    pub output: String,
14}
15
16///Implements app state struct.
17#[derive(Debug, Clone)]
18pub struct AppState {
19    counter: u32,
20}
21
22///Implement getters, setters and constructor for `AppState`.
23impl AppState {
24    pub fn new() -> Self {
25        Self { counter: 0 }
26    }
27    pub fn get_counter(&self) -> &u32 {
28        &self.counter
29    }
30    pub fn increment(&mut self) {
31        self.counter += 1;
32    }
33}
34
35///Used in parsing RestCountries API
36#[derive(Serialize, Deserialize, Debug)]
37pub struct Country {
38    name: Name,
39}
40
41///Used in parsing RestCountries API
42#[derive(Serialize, Deserialize, Debug)]
43pub struct Name {
44    common: String,
45    official: String,
46}
47
48///Used in parsing RestCountries API as query parameters
49#[derive(Deserialize, Debug)]
50pub struct CountryQueryParams {
51    pub name: String,
52}