From da32c1bb4992d68fe8170955484c9717611f94c0 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 31 Jul 2022 15:30:50 +0100 Subject: [PATCH] rename settings modules --- actix-settings/src/lib.rs | 15 +++++++-------- actix-settings/src/{core.rs => parse.rs} | 2 +- actix-settings/src/{actix => settings}/address.rs | 2 +- actix-settings/src/{actix => settings}/backlog.rs | 4 ++-- .../src/{actix => settings}/keep_alive.rs | 4 ++-- .../{actix => settings}/max_connection_rate.rs | 4 ++-- .../src/{actix => settings}/max_connections.rs | 4 ++-- actix-settings/src/{actix.rs => settings/mod.rs} | 0 actix-settings/src/{actix => settings}/mode.rs | 9 ++++----- .../src/{actix => settings}/num_workers.rs | 4 ++-- actix-settings/src/{actix => settings}/timeout.rs | 4 ++-- actix-settings/src/{actix => settings}/tls.rs | 0 12 files changed, 25 insertions(+), 27 deletions(-) rename actix-settings/src/{core.rs => parse.rs} (97%) rename actix-settings/src/{actix => settings}/address.rs (98%) rename actix-settings/src/{actix => settings}/backlog.rs (93%) rename actix-settings/src/{actix => settings}/keep_alive.rs (95%) rename actix-settings/src/{actix => settings}/max_connection_rate.rs (94%) rename actix-settings/src/{actix => settings}/max_connections.rs (93%) rename actix-settings/src/{actix.rs => settings/mod.rs} (100%) rename actix-settings/src/{actix => settings}/mode.rs (70%) rename actix-settings/src/{actix => settings}/num_workers.rs (93%) rename actix-settings/src/{actix => settings}/timeout.rs (96%) rename actix-settings/src/{actix => settings}/tls.rs (100%) diff --git a/actix-settings/src/lib.rs b/actix-settings/src/lib.rs index bb7052f44..55742f7e2 100644 --- a/actix-settings/src/lib.rs +++ b/actix-settings/src/lib.rs @@ -20,17 +20,17 @@ use serde::{de, Deserialize}; #[macro_use] mod error; -mod actix; -mod core; +mod parse; +mod settings; -pub use self::actix::{ +pub use self::error::{AtError, AtResult}; +pub use self::parse::Parse; +pub use self::settings::{ ActixSettings, Address, Backlog, KeepAlive, MaxConnectionRate, MaxConnections, Mode, NumWorkers, Timeout, Tls, }; -pub use self::core::Parse; -pub use self::error::{AtError, AtResult}; -#[derive(Debug, Clone, Deserialize, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize)] #[serde(bound = "A: Deserialize<'de>")] pub struct BasicSettings { pub actix: ActixSettings, @@ -648,10 +648,9 @@ mod tests { } #[derive(Debug, Clone, PartialEq, Eq, Deserialize)] + #[serde(rename_all = "kebab-case")] struct AppSettings { - #[serde(rename = "example-name")] example_name: String, - #[serde(rename = "nested-field")] nested_field: NestedSetting, } diff --git a/actix-settings/src/core.rs b/actix-settings/src/parse.rs similarity index 97% rename from actix-settings/src/core.rs rename to actix-settings/src/parse.rs index 36df38c9e..b13493bfa 100644 --- a/actix-settings/src/core.rs +++ b/actix-settings/src/parse.rs @@ -1,6 +1,6 @@ use std::{path::PathBuf, str::FromStr}; -use crate::error::AtError; +use crate::AtError; pub trait Parse: Sized { fn parse(string: &str) -> Result; diff --git a/actix-settings/src/actix/address.rs b/actix-settings/src/settings/address.rs similarity index 98% rename from actix-settings/src/actix/address.rs rename to actix-settings/src/settings/address.rs index e6af25116..42224143f 100644 --- a/actix-settings/src/actix/address.rs +++ b/actix-settings/src/settings/address.rs @@ -2,7 +2,7 @@ use once_cell::sync::Lazy; use regex::Regex; use serde::Deserialize; -use crate::{core::Parse, error::AtError}; +use crate::{AtError, Parse}; static ADDR_REGEX: Lazy = Lazy::new(|| { Regex::new( diff --git a/actix-settings/src/actix/backlog.rs b/actix-settings/src/settings/backlog.rs similarity index 93% rename from actix-settings/src/actix/backlog.rs rename to actix-settings/src/settings/backlog.rs index 882e01ae9..5e4eecdef 100644 --- a/actix-settings/src/actix/backlog.rs +++ b/actix-settings/src/settings/backlog.rs @@ -2,7 +2,7 @@ use std::fmt; use serde::de; -use crate::{core::Parse, error::AtError}; +use crate::{AtError, AtResult, Parse}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Backlog { @@ -11,7 +11,7 @@ pub enum Backlog { } impl Parse for Backlog { - fn parse(string: &str) -> std::result::Result { + fn parse(string: &str) -> AtResult { match string { "default" => Ok(Backlog::Default), string => match string.parse::() { diff --git a/actix-settings/src/actix/keep_alive.rs b/actix-settings/src/settings/keep_alive.rs similarity index 95% rename from actix-settings/src/actix/keep_alive.rs rename to actix-settings/src/settings/keep_alive.rs index 3879f7da7..55e7d0893 100644 --- a/actix-settings/src/actix/keep_alive.rs +++ b/actix-settings/src/settings/keep_alive.rs @@ -4,7 +4,7 @@ use once_cell::sync::Lazy; use regex::Regex; use serde::de; -use crate::{core::Parse, error::AtError}; +use crate::{AtError, AtResult, Parse}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum KeepAlive { @@ -15,7 +15,7 @@ pub enum KeepAlive { } impl Parse for KeepAlive { - fn parse(string: &str) -> std::result::Result { + fn parse(string: &str) -> AtResult { pub(crate) static FMT: Lazy = Lazy::new(|| Regex::new(r"^\d+ seconds$").expect("Failed to compile regex: FMT")); diff --git a/actix-settings/src/actix/max_connection_rate.rs b/actix-settings/src/settings/max_connection_rate.rs similarity index 94% rename from actix-settings/src/actix/max_connection_rate.rs rename to actix-settings/src/settings/max_connection_rate.rs index c36b09e2b..029daba7f 100644 --- a/actix-settings/src/actix/max_connection_rate.rs +++ b/actix-settings/src/settings/max_connection_rate.rs @@ -2,7 +2,7 @@ use std::fmt; use serde::de; -use crate::{core::Parse, error::AtError}; +use crate::{AtError, AtResult, Parse}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum MaxConnectionRate { @@ -11,7 +11,7 @@ pub enum MaxConnectionRate { } impl Parse for MaxConnectionRate { - fn parse(string: &str) -> std::result::Result { + fn parse(string: &str) -> AtResult { match string { "default" => Ok(MaxConnectionRate::Default), string => match string.parse::() { diff --git a/actix-settings/src/actix/max_connections.rs b/actix-settings/src/settings/max_connections.rs similarity index 93% rename from actix-settings/src/actix/max_connections.rs rename to actix-settings/src/settings/max_connections.rs index 90d2858bc..b50ba3aeb 100644 --- a/actix-settings/src/actix/max_connections.rs +++ b/actix-settings/src/settings/max_connections.rs @@ -2,7 +2,7 @@ use std::fmt; use serde::de; -use crate::{core::Parse, error::AtError}; +use crate::{AtError, AtResult, Parse}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum MaxConnections { @@ -11,7 +11,7 @@ pub enum MaxConnections { } impl Parse for MaxConnections { - fn parse(string: &str) -> std::result::Result { + fn parse(string: &str) -> AtResult { match string { "default" => Ok(MaxConnections::Default), string => match string.parse::() { diff --git a/actix-settings/src/actix.rs b/actix-settings/src/settings/mod.rs similarity index 100% rename from actix-settings/src/actix.rs rename to actix-settings/src/settings/mod.rs diff --git a/actix-settings/src/actix/mode.rs b/actix-settings/src/settings/mode.rs similarity index 70% rename from actix-settings/src/actix/mode.rs rename to actix-settings/src/settings/mode.rs index 6b98ae09e..a590106bd 100644 --- a/actix-settings/src/actix/mode.rs +++ b/actix-settings/src/settings/mode.rs @@ -1,18 +1,17 @@ use serde::Deserialize; -use crate::{core::Parse, error::AtError}; +use crate::{AtResult, Parse}; +/// #[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize)] +#[serde(rename_all = "lowercase")] pub enum Mode { - #[serde(rename = "development")] Development, - - #[serde(rename = "production")] Production, } impl Parse for Mode { - fn parse(string: &str) -> std::result::Result { + fn parse(string: &str) -> AtResult { match string { "development" => Ok(Self::Development), "production" => Ok(Self::Production), diff --git a/actix-settings/src/actix/num_workers.rs b/actix-settings/src/settings/num_workers.rs similarity index 93% rename from actix-settings/src/actix/num_workers.rs rename to actix-settings/src/settings/num_workers.rs index 513931c0f..a0d6755bb 100644 --- a/actix-settings/src/actix/num_workers.rs +++ b/actix-settings/src/settings/num_workers.rs @@ -2,7 +2,7 @@ use std::fmt; use serde::de; -use crate::{core::Parse, error::AtError}; +use crate::{AtError, AtResult, Parse}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum NumWorkers { @@ -11,7 +11,7 @@ pub enum NumWorkers { } impl Parse for NumWorkers { - fn parse(string: &str) -> std::result::Result { + fn parse(string: &str) -> AtResult { match string { "default" => Ok(NumWorkers::Default), string => match string.parse::() { diff --git a/actix-settings/src/actix/timeout.rs b/actix-settings/src/settings/timeout.rs similarity index 96% rename from actix-settings/src/actix/timeout.rs rename to actix-settings/src/settings/timeout.rs index ca28b6e77..6661c381d 100644 --- a/actix-settings/src/actix/timeout.rs +++ b/actix-settings/src/settings/timeout.rs @@ -4,7 +4,7 @@ use once_cell::sync::Lazy; use regex::Regex; use serde::de; -use crate::{core::Parse, error::AtError}; +use crate::{AtError, AtResult, Parse}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Timeout { @@ -14,7 +14,7 @@ pub enum Timeout { } impl Parse for Timeout { - fn parse(string: &str) -> std::result::Result { + fn parse(string: &str) -> AtResult { pub static FMT: Lazy = Lazy::new(|| { Regex::new(r"^\d+ (milliseconds|seconds)$").expect("Failed to compile regex: FMT") }); diff --git a/actix-settings/src/actix/tls.rs b/actix-settings/src/settings/tls.rs similarity index 100% rename from actix-settings/src/actix/tls.rs rename to actix-settings/src/settings/tls.rs