pub use hyper::Method as RequestMethod;
pub use hyper::StatusCode;
pub use url::Url;
use bytes::Bytes;
use std::fmt::{self, Display, Formatter};
use std::ops::Deref;
use std::str::{self, Utf8Error};
string_enums! {
#[derive(Clone, Debug)]
pub enum FilterLevel {
:None("none"),
:Low("low"),
:Medium("medium");
:Custom(_),
}
#[derive(Clone, Debug)]
pub enum With {
:User("user"),
:Following("following");
:Custom(_),
}
}
#[derive(Clone, Default, PartialEq, PartialOrd, Ord, Eq, Debug, Hash)]
pub struct JsonStr {
inner: Bytes,
}
impl JsonStr {
#[doc(hidden)]
pub fn from_utf8(v: Bytes) -> Result<Self, Utf8Error> {
str::from_utf8(&v)?;
unsafe { Ok(JsonStr::from_utf8_unchecked(v)) }
}
pub fn from_static(s: &'static str) -> Self {
JsonStr {
inner: Bytes::from_static(s.as_ref()),
}
}
#[doc(hidden)]
pub unsafe fn from_utf8_unchecked(v: Bytes) -> Self {
JsonStr {
inner: v,
}
}
pub fn as_str(&self) -> &str {
unsafe { str::from_utf8_unchecked(&self.inner) }
}
}
impl AsRef<str> for JsonStr {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl Deref for JsonStr {
type Target = str;
fn deref(&self) -> &str {
self.as_str()
}
}
impl Display for JsonStr {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
self.as_str().fmt(f)
}
}
impl From<String> for JsonStr {
fn from(s: String) -> Self {
JsonStr {
inner: s.into_bytes().into(),
}
}
}
impl<'a> From<&'a str> for JsonStr {
fn from(s: &'a str) -> Self {
JsonStr {
inner: s.into(),
}
}
}
impl From<JsonStr> for Bytes {
fn from(s: JsonStr) -> Self {
s.inner
}
}
impl ::std::default::Default for FilterLevel {
fn default() -> Self {
FilterLevel::None
}
}