use crate::protocol::handshake::ProtocolVersion;
pub const DEFAULT_HOST: &str = "127.0.0.1";
pub const DEFAULT_TCP_PORT: u16 = 2003;
pub const DEFAULT_TLS_PORT: u16 = 2002;
#[derive(Debug, Clone, PartialEq)]
pub struct Config {
host: Box<str>,
port: u16,
username: Box<str>,
password: Box<str>,
pub(crate) protocol: ProtocolVersion,
}
impl Config {
fn _new(
host: Box<str>,
port: u16,
username: Box<str>,
password: Box<str>,
protocol: ProtocolVersion,
) -> Self {
Self {
host,
port,
username,
password,
protocol,
}
}
pub fn new_default(username: &str, password: &str) -> Self {
Self::new(DEFAULT_HOST, DEFAULT_TCP_PORT, username, password)
}
pub fn new(host: &str, port: u16, username: &str, password: &str) -> Self {
Self::_new(
host.into(),
port,
username.into(),
password.into(),
ProtocolVersion::V2_0,
)
}
pub fn host(&self) -> &str {
self.host.as_ref()
}
pub fn port(&self) -> u16 {
self.port
}
pub fn username(&self) -> &str {
self.username.as_ref()
}
pub fn password(&self) -> &str {
self.password.as_ref()
}
}