mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-27 17:22:57 +01:00
rename settings modules
This commit is contained in:
parent
90766e5d68
commit
da32c1bb49
@ -20,17 +20,17 @@ use serde::{de, Deserialize};
|
|||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod error;
|
mod error;
|
||||||
mod actix;
|
mod parse;
|
||||||
mod core;
|
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,
|
ActixSettings, Address, Backlog, KeepAlive, MaxConnectionRate, MaxConnections, Mode,
|
||||||
NumWorkers, Timeout, Tls,
|
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>")]
|
#[serde(bound = "A: Deserialize<'de>")]
|
||||||
pub struct BasicSettings<A> {
|
pub struct BasicSettings<A> {
|
||||||
pub actix: ActixSettings,
|
pub actix: ActixSettings,
|
||||||
@ -648,10 +648,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
struct AppSettings {
|
struct AppSettings {
|
||||||
#[serde(rename = "example-name")]
|
|
||||||
example_name: String,
|
example_name: String,
|
||||||
#[serde(rename = "nested-field")]
|
|
||||||
nested_field: NestedSetting,
|
nested_field: NestedSetting,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::{path::PathBuf, str::FromStr};
|
use std::{path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
use crate::error::AtError;
|
use crate::AtError;
|
||||||
|
|
||||||
pub trait Parse: Sized {
|
pub trait Parse: Sized {
|
||||||
fn parse(string: &str) -> Result<Self, AtError>;
|
fn parse(string: &str) -> Result<Self, AtError>;
|
@ -2,7 +2,7 @@ use once_cell::sync::Lazy;
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::{core::Parse, error::AtError};
|
use crate::{AtError, Parse};
|
||||||
|
|
||||||
static ADDR_REGEX: Lazy<Regex> = Lazy::new(|| {
|
static ADDR_REGEX: Lazy<Regex> = Lazy::new(|| {
|
||||||
Regex::new(
|
Regex::new(
|
@ -2,7 +2,7 @@ use std::fmt;
|
|||||||
|
|
||||||
use serde::de;
|
use serde::de;
|
||||||
|
|
||||||
use crate::{core::Parse, error::AtError};
|
use crate::{AtError, AtResult, Parse};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum Backlog {
|
pub enum Backlog {
|
||||||
@ -11,7 +11,7 @@ pub enum Backlog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for Backlog {
|
impl Parse for Backlog {
|
||||||
fn parse(string: &str) -> std::result::Result<Self, AtError> {
|
fn parse(string: &str) -> AtResult<Self> {
|
||||||
match string {
|
match string {
|
||||||
"default" => Ok(Backlog::Default),
|
"default" => Ok(Backlog::Default),
|
||||||
string => match string.parse::<usize>() {
|
string => match string.parse::<usize>() {
|
@ -4,7 +4,7 @@ use once_cell::sync::Lazy;
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::de;
|
use serde::de;
|
||||||
|
|
||||||
use crate::{core::Parse, error::AtError};
|
use crate::{AtError, AtResult, Parse};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum KeepAlive {
|
pub enum KeepAlive {
|
||||||
@ -15,7 +15,7 @@ pub enum KeepAlive {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for KeepAlive {
|
impl Parse for KeepAlive {
|
||||||
fn parse(string: &str) -> std::result::Result<Self, AtError> {
|
fn parse(string: &str) -> AtResult<Self> {
|
||||||
pub(crate) static FMT: Lazy<Regex> =
|
pub(crate) static FMT: Lazy<Regex> =
|
||||||
Lazy::new(|| Regex::new(r"^\d+ seconds$").expect("Failed to compile regex: FMT"));
|
Lazy::new(|| Regex::new(r"^\d+ seconds$").expect("Failed to compile regex: FMT"));
|
||||||
|
|
@ -2,7 +2,7 @@ use std::fmt;
|
|||||||
|
|
||||||
use serde::de;
|
use serde::de;
|
||||||
|
|
||||||
use crate::{core::Parse, error::AtError};
|
use crate::{AtError, AtResult, Parse};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum MaxConnectionRate {
|
pub enum MaxConnectionRate {
|
||||||
@ -11,7 +11,7 @@ pub enum MaxConnectionRate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for MaxConnectionRate {
|
impl Parse for MaxConnectionRate {
|
||||||
fn parse(string: &str) -> std::result::Result<Self, AtError> {
|
fn parse(string: &str) -> AtResult<Self> {
|
||||||
match string {
|
match string {
|
||||||
"default" => Ok(MaxConnectionRate::Default),
|
"default" => Ok(MaxConnectionRate::Default),
|
||||||
string => match string.parse::<usize>() {
|
string => match string.parse::<usize>() {
|
@ -2,7 +2,7 @@ use std::fmt;
|
|||||||
|
|
||||||
use serde::de;
|
use serde::de;
|
||||||
|
|
||||||
use crate::{core::Parse, error::AtError};
|
use crate::{AtError, AtResult, Parse};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum MaxConnections {
|
pub enum MaxConnections {
|
||||||
@ -11,7 +11,7 @@ pub enum MaxConnections {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for MaxConnections {
|
impl Parse for MaxConnections {
|
||||||
fn parse(string: &str) -> std::result::Result<Self, AtError> {
|
fn parse(string: &str) -> AtResult<Self> {
|
||||||
match string {
|
match string {
|
||||||
"default" => Ok(MaxConnections::Default),
|
"default" => Ok(MaxConnections::Default),
|
||||||
string => match string.parse::<usize>() {
|
string => match string.parse::<usize>() {
|
@ -1,18 +1,17 @@
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::{core::Parse, error::AtError};
|
use crate::{AtResult, Parse};
|
||||||
|
|
||||||
|
///
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
pub enum Mode {
|
pub enum Mode {
|
||||||
#[serde(rename = "development")]
|
|
||||||
Development,
|
Development,
|
||||||
|
|
||||||
#[serde(rename = "production")]
|
|
||||||
Production,
|
Production,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for Mode {
|
impl Parse for Mode {
|
||||||
fn parse(string: &str) -> std::result::Result<Self, AtError> {
|
fn parse(string: &str) -> AtResult<Self> {
|
||||||
match string {
|
match string {
|
||||||
"development" => Ok(Self::Development),
|
"development" => Ok(Self::Development),
|
||||||
"production" => Ok(Self::Production),
|
"production" => Ok(Self::Production),
|
@ -2,7 +2,7 @@ use std::fmt;
|
|||||||
|
|
||||||
use serde::de;
|
use serde::de;
|
||||||
|
|
||||||
use crate::{core::Parse, error::AtError};
|
use crate::{AtError, AtResult, Parse};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum NumWorkers {
|
pub enum NumWorkers {
|
||||||
@ -11,7 +11,7 @@ pub enum NumWorkers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for NumWorkers {
|
impl Parse for NumWorkers {
|
||||||
fn parse(string: &str) -> std::result::Result<Self, AtError> {
|
fn parse(string: &str) -> AtResult<Self> {
|
||||||
match string {
|
match string {
|
||||||
"default" => Ok(NumWorkers::Default),
|
"default" => Ok(NumWorkers::Default),
|
||||||
string => match string.parse::<usize>() {
|
string => match string.parse::<usize>() {
|
@ -4,7 +4,7 @@ use once_cell::sync::Lazy;
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::de;
|
use serde::de;
|
||||||
|
|
||||||
use crate::{core::Parse, error::AtError};
|
use crate::{AtError, AtResult, Parse};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum Timeout {
|
pub enum Timeout {
|
||||||
@ -14,7 +14,7 @@ pub enum Timeout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for Timeout {
|
impl Parse for Timeout {
|
||||||
fn parse(string: &str) -> std::result::Result<Self, AtError> {
|
fn parse(string: &str) -> AtResult<Self> {
|
||||||
pub static FMT: Lazy<Regex> = Lazy::new(|| {
|
pub static FMT: Lazy<Regex> = Lazy::new(|| {
|
||||||
Regex::new(r"^\d+ (milliseconds|seconds)$").expect("Failed to compile regex: FMT")
|
Regex::new(r"^\d+ (milliseconds|seconds)$").expect("Failed to compile regex: FMT")
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user