simplist 0.0.5

plain and simple http, for when you just want to make a darn request! supports tokio-based async, traditional sync and async-await models.
Documentation
use std;
use std::fmt::Display;
use std::str::FromStr;

use hyper::Uri;
use hyper::error::UriError;

use simplist::HttpError;



/// simple access to a url and its components.
///
/// this is an ultra thin wrapper on top of a [`hyper::Uri`](https://docs.rs/hyper/0.11.1/hyper/struct.Uri.html).
///
/// # examples
///
/// ```
/// let url = "https://hinaria.com".parse()?;
/// ```
#[derive(Clone, Debug, Default, Hash, PartialEq, Eq)]
pub struct Url {
    underlying: Uri,
}

impl Url {
    /// returns the path component for this url.
    ///
    /// # examples
    ///
    /// ```
    /// let url: Url = "https://hinaria.com/hello/index.html?q=search".parse()?;
    ///
    /// assert_eq!(url.path(), "/hello/index.html");
    /// ```
    pub fn path(&self) -> &str {
        self.underlying.path()
    }

    /// returns the scheme component for this url.
    ///
    /// # examples
    ///
    /// ```
    /// let url: Url = "https://hinaria.com/hello/index.html?q=search".parse()?;
    ///
    /// assert_eq!(url.scheme(), Some("https"));
    /// ```
    pub fn scheme(&self) -> Option<&str> {
        self.underlying.scheme()
    }

    /// returns the authority component for this url.
    ///
    /// # examples
    ///
    /// ```
    /// let url: Url = "https://hinaria.com/hello/index.html?q=search".parse()?;
    ///
    /// assert_eq!(url.authority(), Some("hinaria.com"));
    /// ```
    pub fn authority(&self) -> Option<&str> {
        self.underlying.authority()
    }

    /// returns the host component for this url.
    ///
    /// # examples
    ///
    /// ```
    /// let url: Url = "https://hinaria.com/hello/index.html?q=search".parse()?;
    ///
    /// assert_eq!(url.host(), Some("hinaria.com"));
    /// ```
    pub fn host(&self) -> Option<&str> {
        self.underlying.host()
    }

    /// returns the port component for this url.
    ///
    /// # examples
    ///
    /// ```
    /// let url: Url = "https://hinaria.com/hello/index.html?q=search".parse()?;
    ///
    /// assert_eq!(url.port(), None);
    /// ```
    pub fn port(&self) -> Option<u16> {
        self.underlying.port()
    }

    /// returns the query component for this url.
    ///
    /// # examples
    ///
    /// ```
    /// let url: Url = "https://hinaria.com/hello/index.html?q=search".parse()?;
    ///
    /// assert_eq!(url.query(), Some("q=search"));
    /// ```
    pub fn query(&self) -> Option<&str> {
        self.underlying.query()
    }

    /// returns the is_absolute component for this url.
    ///
    /// # examples
    ///
    /// ```
    /// let url: Url = "https://hinaria.com/hello/index.html?q=search".parse()?;
    ///
    /// assert_eq!(url.is_absolute(), true);
    /// ```
    pub fn is_absolute(&self) -> bool {
        self.underlying.is_absolute()
    }
}

impl FromStr for Url {
    type Err = UriError;

    fn from_str(string: &str) -> Result<Url, UriError> {
        Ok(Url { underlying: string.parse()? })
    }
}

impl Display for Url {
    fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
        self.underlying.fmt(formatter)
    }
}

impl Into<Uri> for Url {
    fn into(self) -> Uri {
        self.underlying
    }
}



/// freely convertible to a [`Url`](struct.Url.html).
pub trait IntoUrl {
    fn as_url(self) -> Result<Url, HttpError>;
}

impl IntoUrl for String {
    fn as_url(self) -> Result<Url, HttpError> {
        let v = self.parse()?;
        Ok(v)
    }
}

impl<'a> IntoUrl for &'a str {
    fn as_url(self) -> Result<Url, HttpError> {
        let v = self.parse()?;
        Ok(v)
    }
}

impl IntoUrl for Url {
    fn as_url(self) -> Result<Url, HttpError> {
        Ok(self)
    }
}