2016-12-20 03:50:27 +00:00
|
|
|
//! Types that map to concepts in HTTP.
|
2016-10-18 02:29:58 +00:00
|
|
|
//!
|
|
|
|
//! This module exports types that map to HTTP concepts or to the underlying
|
|
|
|
//! HTTP library when needed. Because the underlying HTTP library is likely to
|
|
|
|
//! change (see <a
|
2016-12-20 03:50:27 +00:00
|
|
|
//! href="https://github.com/SergioBenitez/Rocket/issues/17">#17</a>), types in
|
|
|
|
//! [hyper](hyper/index.html) should be considered unstable.
|
2016-10-04 00:09:13 +00:00
|
|
|
pub mod hyper;
|
2016-10-04 00:25:27 +00:00
|
|
|
pub mod uri;
|
2016-10-04 00:09:13 +00:00
|
|
|
|
2017-03-21 09:04:07 +00:00
|
|
|
#[macro_use]
|
|
|
|
mod known_media_types;
|
2016-10-04 00:09:13 +00:00
|
|
|
mod cookies;
|
2017-03-08 11:28:12 +00:00
|
|
|
mod session;
|
2016-10-04 00:09:13 +00:00
|
|
|
mod method;
|
2017-03-21 09:04:07 +00:00
|
|
|
mod media_type;
|
2016-10-04 00:09:13 +00:00
|
|
|
mod content_type;
|
2016-12-15 08:47:31 +00:00
|
|
|
mod status;
|
|
|
|
mod header;
|
2017-03-27 08:53:45 +00:00
|
|
|
mod accept;
|
2017-03-28 10:10:18 +00:00
|
|
|
|
|
|
|
pub(crate) mod parse;
|
2017-01-05 08:14:44 +00:00
|
|
|
|
2017-03-27 08:53:45 +00:00
|
|
|
// We need to export these for codegen, but otherwise it's unnecessary.
|
2017-01-05 08:14:44 +00:00
|
|
|
// TODO: Expose a `const fn` from ContentType when possible. (see RFC#1817)
|
2017-03-30 22:38:51 +00:00
|
|
|
pub mod uncased;
|
2017-03-24 05:41:42 +00:00
|
|
|
#[doc(hidden)] pub use self::parse::IndexedStr;
|
|
|
|
#[doc(hidden)] pub use self::media_type::MediaParams;
|
2016-10-04 00:09:13 +00:00
|
|
|
|
|
|
|
pub use self::method::Method;
|
|
|
|
pub use self::content_type::ContentType;
|
2017-03-27 08:53:45 +00:00
|
|
|
pub use self::accept::{Accept, WeightedMediaType};
|
2016-12-20 03:46:49 +00:00
|
|
|
pub use self::status::{Status, StatusClass};
|
2016-12-15 20:37:17 +00:00
|
|
|
pub use self::header::{Header, HeaderMap};
|
2016-10-18 02:29:58 +00:00
|
|
|
|
2017-03-24 05:41:42 +00:00
|
|
|
pub use self::media_type::MediaType;
|
2017-03-08 11:28:12 +00:00
|
|
|
pub use self::cookies::*;
|
|
|
|
pub use self::session::*;
|
2017-03-29 11:08:53 +00:00
|
|
|
|
|
|
|
use smallvec::{Array, SmallVec};
|
|
|
|
|
|
|
|
pub trait IntoCollection<T> {
|
|
|
|
fn into_collection<A: Array<Item=T>>(self) -> SmallVec<A>;
|
|
|
|
fn mapped<U, F: FnMut(T) -> U, A: Array<Item=U>>(self, f: F) -> SmallVec<A>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> IntoCollection<T> for T {
|
|
|
|
#[inline]
|
|
|
|
fn into_collection<A: Array<Item=T>>(self) -> SmallVec<A> {
|
|
|
|
let mut vec = SmallVec::new();
|
|
|
|
vec.push(self);
|
|
|
|
vec
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn mapped<U, F: FnMut(T) -> U, A: Array<Item=U>>(self, mut f: F) -> SmallVec<A> {
|
|
|
|
f(self).into_collection()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> IntoCollection<T> for Vec<T> {
|
|
|
|
#[inline(always)]
|
|
|
|
fn into_collection<A: Array<Item=T>>(self) -> SmallVec<A> {
|
|
|
|
SmallVec::from_vec(self)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn mapped<U, F: FnMut(T) -> U, A: Array<Item=U>>(self, mut f: F) -> SmallVec<A> {
|
|
|
|
self.into_iter().map(|item| f(item)).collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, T: Clone> IntoCollection<T> for &'a [T] {
|
|
|
|
#[inline(always)]
|
|
|
|
fn into_collection<A: Array<Item=T>>(self) -> SmallVec<A> {
|
|
|
|
self.iter().cloned().collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn mapped<U, F: FnMut(T) -> U, A: Array<Item=U>>(self, mut f: F) -> SmallVec<A> {
|
|
|
|
self.iter().cloned().map(|item| f(item)).collect()
|
|
|
|
}
|
|
|
|
}
|