use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Concurrency {
Sync,
Async,
}
impl Display for Concurrency {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match &self {
Self::Sync => write!(f, "sync"),
Self::Async => write!(f, "async"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BasicAuth {
pub username: String,
pub password: Option<String>,
}
impl BasicAuth {
pub fn new<S1, S2>(username: S1, password: Option<S2>) -> BasicAuth
where
S1: Into<String>,
S2: Into<String>,
{
BasicAuth {
username: username.into(),
password: password.map(|password| password.into()),
}
}
pub fn some<S1, S2>(username: S1, password: Option<S2>) -> Option<BasicAuth>
where
S1: Into<String>,
S2: Into<String>,
{
Some(BasicAuth {
username: username.into(),
password: password.map(|password| password.into()),
})
}
}