Merge pull request #256 from mozilla/pb/refactor-enum-defaults
https://github.com/mozilla/fxa-email-service/pull/256 r=vladikoff
This commit is contained in:
Коммит
659ad55473
|
@ -11,14 +11,8 @@ use serde::de::Error;
|
|||
|
||||
use types::error::{AppError, AppErrorKind};
|
||||
|
||||
enum_boilerplate!(Env ("env", InvalidEnv) {
|
||||
enum_boilerplate!(Env ("env", Dev, InvalidEnv) {
|
||||
Dev => "dev",
|
||||
Prod => "production",
|
||||
Test => "test",
|
||||
});
|
||||
|
||||
impl Default for Env {
|
||||
fn default() -> Self {
|
||||
Env::Dev
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,26 +11,14 @@ use serde::de::Error;
|
|||
|
||||
use types::error::{AppError, AppErrorKind};
|
||||
|
||||
enum_boilerplate!(LogLevel ("log level", InvalidLogLevel) {
|
||||
enum_boilerplate!(LogLevel ("log level", Normal, InvalidLogLevel) {
|
||||
Normal => "normal",
|
||||
Debug => "debug",
|
||||
Critical => "critical",
|
||||
Off => "off",
|
||||
});
|
||||
|
||||
impl Default for LogLevel {
|
||||
fn default() -> Self {
|
||||
LogLevel::Normal
|
||||
}
|
||||
}
|
||||
|
||||
enum_boilerplate!(LogFormat ("log format", InvalidLogFormat) {
|
||||
enum_boilerplate!(LogFormat ("log format", Mozlog, InvalidLogFormat) {
|
||||
Mozlog => "mozlog",
|
||||
Pretty => "pretty",
|
||||
});
|
||||
|
||||
impl Default for LogFormat {
|
||||
fn default() -> Self {
|
||||
LogFormat::Mozlog
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
//! miscellaneous generally-used types.
|
||||
|
||||
macro_rules! enum_boilerplate {
|
||||
($name:ident ($description:expr, $error:ident) {
|
||||
($name:ident ($description:expr, $default:ident, $error:ident) {
|
||||
$($variant:ident => $serialization:expr,)+
|
||||
}) => {
|
||||
#[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 {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(formatter, "{}", self.as_ref())
|
||||
|
|
|
@ -11,16 +11,10 @@ use serde::de::Error;
|
|||
|
||||
use types::error::{AppError, AppErrorKind};
|
||||
|
||||
enum_boilerplate!(Provider ("env", InvalidPayload) {
|
||||
enum_boilerplate!(Provider ("env", Ses, InvalidPayload) {
|
||||
Mock => "mock",
|
||||
Sendgrid => "sendgrid",
|
||||
Ses => "ses",
|
||||
Smtp => "smtp",
|
||||
SocketLabs => "socketlabs",
|
||||
});
|
||||
|
||||
impl Default for Provider {
|
||||
fn default() -> Self {
|
||||
Provider::Ses
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче