1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-26 18:37:41 +02:00

rename AtError => Error (#275)

* refactor(settings)!: rename AtError => Error

and remove AtResult from public API

* update changelog

* recover from file metadata errors
This commit is contained in:
Rob Ede
2022-08-10 10:13:34 +02:00
committed by GitHub
parent a325f5dd02
commit e61dbae860
12 changed files with 72 additions and 67 deletions

View File

@ -2,7 +2,7 @@ use once_cell::sync::Lazy;
use regex::Regex;
use serde::Deserialize;
use crate::{AtError, Parse};
use crate::{Error, Parse};
static ADDR_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(
@ -48,14 +48,14 @@ pub struct Address {
}
impl Parse for Address {
fn parse(string: &str) -> Result<Self, AtError> {
fn parse(string: &str) -> Result<Self, Error> {
let mut items = string
.trim()
.trim_start_matches('[')
.trim_end_matches(']')
.split(',');
let parse_error = || AtError::ParseAddressError(string.to_string());
let parse_error = || Error::ParseAddressError(string.to_string());
if !ADDR_REGEX.is_match(string) {
return Err(parse_error());
@ -69,8 +69,8 @@ impl Parse for Address {
}
impl Parse for Vec<Address> {
fn parse(string: &str) -> Result<Self, AtError> {
let parse_error = || AtError::ParseAddressError(string.to_string());
fn parse(string: &str) -> Result<Self, Error> {
let parse_error = || Error::ParseAddressError(string.to_string());
if !ADDR_LIST_REGEX.is_match(string) {
return Err(parse_error());

View File

@ -2,7 +2,7 @@ use std::fmt;
use serde::de;
use crate::{AtError, AtResult, Parse};
use crate::{AsResult, Error, Parse};
/// The maximum number of pending connections.
///
@ -22,7 +22,7 @@ pub enum Backlog {
}
impl Parse for Backlog {
fn parse(string: &str) -> AtResult<Self> {
fn parse(string: &str) -> AsResult<Self> {
match string {
"default" => Ok(Backlog::Default),
string => match string.parse::<usize>() {
@ -57,7 +57,7 @@ impl<'de> de::Deserialize<'de> for Backlog {
{
match Backlog::parse(value) {
Ok(backlog) => Ok(backlog),
Err(AtError::InvalidValue { expected, got, .. }) => Err(
Err(Error::InvalidValue { expected, got, .. }) => Err(
de::Error::invalid_value(de::Unexpected::Str(&got), &expected),
),
Err(_) => unreachable!(),

View File

@ -4,7 +4,7 @@ use once_cell::sync::Lazy;
use regex::Regex;
use serde::de;
use crate::{AtError, AtResult, Parse};
use crate::{AsResult, Error, Parse};
/// The server keep-alive preference.
///
@ -28,7 +28,7 @@ pub enum KeepAlive {
}
impl Parse for KeepAlive {
fn parse(string: &str) -> AtResult<Self> {
fn parse(string: &str) -> AsResult<Self> {
pub(crate) static FMT: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^\d+ seconds$").expect("Failed to compile regex: FMT"));
@ -82,7 +82,7 @@ impl<'de> de::Deserialize<'de> for KeepAlive {
{
match KeepAlive::parse(value) {
Ok(keep_alive) => Ok(keep_alive),
Err(AtError::InvalidValue { expected, got, .. }) => Err(
Err(Error::InvalidValue { expected, got, .. }) => Err(
de::Error::invalid_value(de::Unexpected::Str(&got), &expected),
),
Err(_) => unreachable!(),

View File

@ -2,7 +2,7 @@ use std::fmt;
use serde::de;
use crate::{AtError, AtResult, Parse};
use crate::{AsResult, Error, Parse};
/// The maximum per-worker concurrent TLS connection limit.
///
@ -19,7 +19,7 @@ pub enum MaxConnectionRate {
}
impl Parse for MaxConnectionRate {
fn parse(string: &str) -> AtResult<Self> {
fn parse(string: &str) -> AsResult<Self> {
match string {
"default" => Ok(MaxConnectionRate::Default),
string => match string.parse::<usize>() {
@ -54,7 +54,7 @@ impl<'de> de::Deserialize<'de> for MaxConnectionRate {
{
match MaxConnectionRate::parse(value) {
Ok(max_connection_rate) => Ok(max_connection_rate),
Err(AtError::InvalidValue { expected, got, .. }) => Err(
Err(Error::InvalidValue { expected, got, .. }) => Err(
de::Error::invalid_value(de::Unexpected::Str(&got), &expected),
),
Err(_) => unreachable!(),

View File

@ -2,7 +2,7 @@ use std::fmt;
use serde::de;
use crate::{AtError, AtResult, Parse};
use crate::{AsResult, Error, Parse};
/// The maximum per-worker number of concurrent connections.
///
@ -19,7 +19,7 @@ pub enum MaxConnections {
}
impl Parse for MaxConnections {
fn parse(string: &str) -> AtResult<Self> {
fn parse(string: &str) -> AsResult<Self> {
match string {
"default" => Ok(MaxConnections::Default),
string => match string.parse::<usize>() {
@ -54,7 +54,7 @@ impl<'de> de::Deserialize<'de> for MaxConnections {
{
match MaxConnections::parse(value) {
Ok(max_connections) => Ok(max_connections),
Err(AtError::InvalidValue { expected, got, .. }) => Err(
Err(Error::InvalidValue { expected, got, .. }) => Err(
de::Error::invalid_value(de::Unexpected::Str(&got), &expected),
),
Err(_) => unreachable!(),

View File

@ -1,6 +1,6 @@
use serde::Deserialize;
use crate::{AtResult, Parse};
use crate::{AsResult, Parse};
/// Marker of intended deployment environment.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize)]
@ -14,7 +14,7 @@ pub enum Mode {
}
impl Parse for Mode {
fn parse(string: &str) -> AtResult<Self> {
fn parse(string: &str) -> AsResult<Self> {
match string {
"development" => Ok(Self::Development),
"production" => Ok(Self::Production),

View File

@ -2,7 +2,7 @@ use std::fmt;
use serde::de;
use crate::{AtError, AtResult, Parse};
use crate::{AsResult, Error, Parse};
/// The number of workers that the server should start.
///
@ -18,7 +18,7 @@ pub enum NumWorkers {
}
impl Parse for NumWorkers {
fn parse(string: &str) -> AtResult<Self> {
fn parse(string: &str) -> AsResult<Self> {
match string {
"default" => Ok(NumWorkers::Default),
string => match string.parse::<usize>() {
@ -53,7 +53,7 @@ impl<'de> de::Deserialize<'de> for NumWorkers {
{
match NumWorkers::parse(value) {
Ok(num_workers) => Ok(num_workers),
Err(AtError::InvalidValue { expected, got, .. }) => Err(
Err(Error::InvalidValue { expected, got, .. }) => Err(
de::Error::invalid_value(de::Unexpected::Str(&got), &expected),
),
Err(_) => unreachable!(),

View File

@ -4,7 +4,7 @@ use once_cell::sync::Lazy;
use regex::Regex;
use serde::de;
use crate::{AtError, AtResult, Parse};
use crate::{AsResult, Error, Parse};
/// A timeout duration in milliseconds or seconds.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@ -20,7 +20,7 @@ pub enum Timeout {
}
impl Parse for Timeout {
fn parse(string: &str) -> AtResult<Self> {
fn parse(string: &str) -> AsResult<Self> {
pub static FMT: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^\d+ (milliseconds|seconds)$").expect("Failed to compile regex: FMT")
});
@ -85,7 +85,7 @@ impl<'de> de::Deserialize<'de> for Timeout {
{
match Timeout::parse(value) {
Ok(num_workers) => Ok(num_workers),
Err(AtError::InvalidValue { expected, got, .. }) => Err(
Err(Error::InvalidValue { expected, got, .. }) => Err(
de::Error::invalid_value(de::Unexpected::Str(&got), &expected),
),
Err(_) => unreachable!(),