refactor(settings): implement Default in enum_boilerplate!
This commit is contained in:
Родитель
0a02f99133
Коммит
a9c9a1bf6f
|
@ -11,14 +11,8 @@ use serde::de::Error;
|
||||||
|
|
||||||
use types::error::{AppError, AppErrorKind};
|
use types::error::{AppError, AppErrorKind};
|
||||||
|
|
||||||
enum_boilerplate!(Env ("env", InvalidEnv) {
|
enum_boilerplate!(Env ("env", Dev, InvalidEnv) {
|
||||||
Dev => "dev",
|
Dev => "dev",
|
||||||
Prod => "production",
|
Prod => "production",
|
||||||
Test => "test",
|
Test => "test",
|
||||||
});
|
});
|
||||||
|
|
||||||
impl Default for Env {
|
|
||||||
fn default() -> Self {
|
|
||||||
Env::Dev
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -11,26 +11,14 @@ use serde::de::Error;
|
||||||
|
|
||||||
use types::error::{AppError, AppErrorKind};
|
use types::error::{AppError, AppErrorKind};
|
||||||
|
|
||||||
enum_boilerplate!(LogLevel ("log level", InvalidLogLevel) {
|
enum_boilerplate!(LogLevel ("log level", Normal, InvalidLogLevel) {
|
||||||
Normal => "normal",
|
Normal => "normal",
|
||||||
Debug => "debug",
|
Debug => "debug",
|
||||||
Critical => "critical",
|
Critical => "critical",
|
||||||
Off => "off",
|
Off => "off",
|
||||||
});
|
});
|
||||||
|
|
||||||
impl Default for LogLevel {
|
enum_boilerplate!(LogFormat ("log format", Mozlog, InvalidLogFormat) {
|
||||||
fn default() -> Self {
|
|
||||||
LogLevel::Normal
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum_boilerplate!(LogFormat ("log format", InvalidLogFormat) {
|
|
||||||
Mozlog => "mozlog",
|
Mozlog => "mozlog",
|
||||||
Pretty => "pretty",
|
Pretty => "pretty",
|
||||||
});
|
});
|
||||||
|
|
||||||
impl Default for LogFormat {
|
|
||||||
fn default() -> Self {
|
|
||||||
LogFormat::Mozlog
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
//! miscellaneous generally-used types.
|
//! miscellaneous generally-used types.
|
||||||
|
|
||||||
macro_rules! enum_boilerplate {
|
macro_rules! enum_boilerplate {
|
||||||
($name:ident ($description:expr, $error:ident) {
|
($name:ident ($description:expr, $default:ident, $error:ident) {
|
||||||
$($variant:ident => $serialization:expr,)+
|
$($variant:ident => $serialization:expr,)+
|
||||||
}) => {
|
}) => {
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
@ -25,6 +25,12 @@ macro_rules! enum_boilerplate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::default::Default for $name {
|
||||||
|
fn default() -> Self {
|
||||||
|
$name::$default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for $name {
|
impl std::fmt::Display for $name {
|
||||||
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
write!(formatter, "{}", self.as_ref())
|
write!(formatter, "{}", self.as_ref())
|
||||||
|
|
|
@ -11,16 +11,10 @@ use serde::de::Error;
|
||||||
|
|
||||||
use types::error::{AppError, AppErrorKind};
|
use types::error::{AppError, AppErrorKind};
|
||||||
|
|
||||||
enum_boilerplate!(Provider ("env", InvalidPayload) {
|
enum_boilerplate!(Provider ("env", Ses, InvalidPayload) {
|
||||||
Mock => "mock",
|
Mock => "mock",
|
||||||
Sendgrid => "sendgrid",
|
Sendgrid => "sendgrid",
|
||||||
Ses => "ses",
|
Ses => "ses",
|
||||||
Smtp => "smtp",
|
Smtp => "smtp",
|
||||||
SocketLabs => "socketlabs",
|
SocketLabs => "socketlabs",
|
||||||
});
|
});
|
||||||
|
|
||||||
impl Default for Provider {
|
|
||||||
fn default() -> Self {
|
|
||||||
Provider::Ses
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче