redisx 0.0.2

Minimal and Asynchronous Redis client for Rust.
Documentation
const DEFAULT_HOST: &str = "localhost";

const DEFAULT_PORT: u16 = 6379;

pub struct Url(url::Url);

// redis :// [: password@] host [: port] [/ database][? [timeout=timeout[d|h|m|s|ms|us|ns]] [&_database=database_]]

// rediss :// [: password@] host [: port] [/ database][? [timeout=timeout[d|h|m|s|ms|us|ns]] [&_database=database_]]

impl Url {
    pub fn parse(url: &str) -> crate::Result<Self> {
        // TODO: Assert that the scheme is valid
        Ok(Url(url::Url::parse(url)?))
    }

    #[inline]
    pub(crate) fn scheme(&self) -> &str {
        self.0.scheme()
    }

    #[inline]
    pub fn host(&self) -> &str {
        let host = self.0.host_str().unwrap_or(DEFAULT_HOST);

        if host.is_empty() {
            DEFAULT_HOST
        } else {
            host
        }
    }

    #[inline]
    pub fn port(&self) -> u16 {
        self.0.port().unwrap_or(DEFAULT_PORT)
    }

    #[inline]
    pub fn database(&self) -> &str {
        // TODO: Fail if path is not an integer

        if self.0.path() == "/" {
            "0"
        } else {
            &self.0.path()[1..]
        }
    }

    #[inline]
    pub fn password(&self) -> Option<&str> {
        self.0.password()
    }
}