From 9a00f91ebc16382b9a843fc2392c8a5a9305ba42 Mon Sep 17 00:00:00 2001 From: Milim Date: Thu, 15 Aug 2024 08:03:10 +0200 Subject: [PATCH] move all config related code into config.rs --- src/config.rs | 31 ++++++++++++++++++-- src/models/mod.rs | 1 - src/models/parser_models.rs | 57 ------------------------------------- src/models/server_models.rs | 2 +- 4 files changed, 30 insertions(+), 61 deletions(-) delete mode 100644 src/models/parser_models.rs diff --git a/src/config.rs b/src/config.rs index 7e6b6a8..0d73683 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,8 +3,6 @@ use figment::{providers::Serialized, Figment}; use serde::{Deserialize, Serialize}; -use crate::models::parser_models::Style; - /// A named struct which stores the parsed config file options. #[derive(Debug, Clone, Deserialize, Serialize)] pub struct Config { @@ -34,6 +32,35 @@ pub struct Config { pub pool_idle_connection_timeout: u8, } +/// A named struct which stores,deserializes, serializes and groups the parsed config file options +/// of theme and colorscheme names into the Style struct which derives the `Clone`, `Serialize` +/// and Deserialize traits where the `Clone` trait is derived for allowing the struct to be +/// cloned and passed to the server as a shared data between all routes except `/robots.txt` and +/// the `Serialize` trait has been derived for allowing the object to be serialized so that it +/// can be passed to handlebars template files and the `Deserialize` trait has been derived in +/// order to allow the deserializing the json back to struct in aggregate function in +/// aggregator.rs and create a new struct out of it and then serialize it back to json and pass +/// it to the template files. +#[derive(Default, Debug, Clone, Deserialize, Serialize)] +pub struct Style { + /// It stores the parsed theme option used to set a theme for the website. + pub theme: String, + /// It stores the parsed colorscheme option used to set a colorscheme for the + /// theme being used. + pub colorscheme: String, + /// It stores the parsed animation option used to set an animation for the + /// theme being used. + pub animation: Option, +} + +/// Configuration options for the rate limiter middleware. +pub struct RateLimiter { + /// The number of request that are allowed within a provided time limit. + pub number_of_requests: u8, + /// The time limit in which the quantity of requests that should be accepted. + pub time_limit: u8, +} + impl Default for Config { fn default() -> Self { Self { diff --git a/src/models/mod.rs b/src/models/mod.rs index 6a7d235..b8a8071 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -4,5 +4,4 @@ pub mod aggregation_models; pub mod engine_models; -pub mod parser_models; pub mod server_models; diff --git a/src/models/parser_models.rs b/src/models/parser_models.rs deleted file mode 100644 index b72c84d..0000000 --- a/src/models/parser_models.rs +++ /dev/null @@ -1,57 +0,0 @@ -//! This module provides public models for handling, storing and serializing parsed config file -//! options from config.lua by grouping them together. - -use serde::{Deserialize, Serialize}; - -/// A named struct which stores,deserializes, serializes and groups the parsed config file options -/// of theme and colorscheme names into the Style struct which derives the `Clone`, `Serialize` -/// and Deserialize traits where the `Clone` trait is derived for allowing the struct to be -/// cloned and passed to the server as a shared data between all routes except `/robots.txt` and -/// the `Serialize` trait has been derived for allowing the object to be serialized so that it -/// can be passed to handlebars template files and the `Deserialize` trait has been derived in -/// order to allow the deserializing the json back to struct in aggregate function in -/// aggregator.rs and create a new struct out of it and then serialize it back to json and pass -/// it to the template files. -#[derive(Default, Debug, Clone, Deserialize, Serialize)] -pub struct Style { - /// It stores the parsed theme option used to set a theme for the website. - pub theme: String, - /// It stores the parsed colorscheme option used to set a colorscheme for the - /// theme being used. - pub colorscheme: String, - /// It stores the parsed animation option used to set an animation for the - /// theme being used. - pub animation: Option, -} - -impl Style { - /// Constructs a new `Style` with the given arguments needed for the struct. - /// - /// # Arguments - /// - /// * `theme` - It takes the parsed theme option used to set a theme for the website. - /// * `colorscheme` - It takes the parsed colorscheme option used to set a colorscheme - /// for the theme being used. - pub fn new(theme: String, colorscheme: String, animation: Option) -> Self { - Style { - theme, - colorscheme, - animation, - } - } -} - -/// Configuration options for the aggregator. -pub struct AggregatorConfig { - /// It stores the option to whether enable or disable random delays between - /// requests. - pub random_delay: bool, -} - -/// Configuration options for the rate limiter middleware. -pub struct RateLimiter { - /// The number of request that are allowed within a provided time limit. - pub number_of_requests: u8, - /// The time limit in which the quantity of requests that should be accepted. - pub time_limit: u8, -} diff --git a/src/models/server_models.rs b/src/models/server_models.rs index dde46cd..a536683 100644 --- a/src/models/server_models.rs +++ b/src/models/server_models.rs @@ -4,7 +4,7 @@ use std::borrow::Cow; use serde::Deserialize; -use super::parser_models::Style; +use crate::config::Style; /// A named struct which deserializes all the user provided search parameters and stores them. #[derive(Deserialize)]