use std::net::IpAddr;
use std::str::FromStr;
use anyhow::{bail, Error, Result};
#[derive(Clone, Debug)]
pub struct Config {
pub host: IpAddr,
pub port: u16,
pub cors: bool,
}
#[derive(Clone, Debug)]
pub struct BasicAuth {
pub username: String,
pub password: String,
}
impl FromStr for BasicAuth {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
let parts = s.split(":").collect::<Vec<&str>>();
if parts.len() != 2 {
bail!("Expected a string with a colon to separe username and password for Basic Authentication.");
}
Ok(BasicAuth {
username: parts[0].into(),
password: parts[1].into(),
})
}
}