Rocket/lib/src/http/mod.rs

84 lines
2.3 KiB
Rust
Raw Normal View History

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.
pub mod hyper;
2016-10-04 00:25:27 +00:00
pub mod uri;
#[macro_use]
mod known_media_types;
mod cookies;
mod session;
mod method;
mod media_type;
mod content_type;
mod status;
mod header;
2017-03-27 08:53:45 +00:00
mod accept;
pub(crate) mod parse;
2017-03-27 08:53:45 +00:00
// We need to export these for codegen, but otherwise it's unnecessary.
// TODO: Expose a `const fn` from ContentType when possible. (see RFC#1817)
#[doc(hidden)] pub mod ascii;
#[doc(hidden)] pub use self::parse::IndexedStr;
#[doc(hidden)] pub use self::media_type::MediaParams;
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};
pub use self::header::{Header, HeaderMap};
2016-10-18 02:29:58 +00:00
pub use self::media_type::MediaType;
pub use self::cookies::*;
pub use self::session::*;
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()
}
}