diff --git a/core/http/Cargo.toml b/core/http/Cargo.toml index a3537d7b..6c29fa17 100644 --- a/core/http/Cargo.toml +++ b/core/http/Cargo.toml @@ -25,7 +25,7 @@ serde = ["uncased/with-serde-alloc", "serde_"] uuid = ["uuid_"] [dependencies] -smallvec = "1.0" +smallvec = { version = "1.11", features = ["const_generics", "const_new"] } percent-encoding = "2" http = "0.2" time = { version = "0.3", features = ["formatting", "macros"] } diff --git a/core/http/src/ext.rs b/core/http/src/ext.rs index e78012e5..65629c58 100644 --- a/core/http/src/ext.rs +++ b/core/http/src/ext.rs @@ -12,12 +12,6 @@ pub trait IntoCollection: Sized { #[doc(hidden)] fn mapped U, A: Array>(self, f: F) -> SmallVec; - - #[doc(hidden)] - fn mapped_vec U>(self, f: F) -> Vec { - let small = self.mapped::(f); - small.into_vec() - } } impl IntoCollection for T { diff --git a/core/http/src/header/accept.rs b/core/http/src/header/accept.rs index 305272a6..c38e4932 100644 --- a/core/http/src/header/accept.rs +++ b/core/http/src/header/accept.rs @@ -3,7 +3,6 @@ use std::str::FromStr; use std::fmt; use smallvec::SmallVec; -use either::Either; use crate::{Header, MediaType}; use crate::ext::IntoCollection; @@ -53,30 +52,21 @@ use crate::parse::parse_accept; /// let response = Response::build().header(Accept::JSON).finalize(); /// ``` #[derive(Debug, Clone)] -pub struct Accept(pub(crate) AcceptParams); +pub struct Accept(pub(crate) SmallVec<[QMediaType; 1]>); /// A `MediaType` with an associated quality value. #[derive(Debug, Clone, PartialEq)] pub struct QMediaType(pub MediaType, pub Option); -// NOTE: `Static` is needed for `const` items. Need `const SmallVec::new`. -#[derive(Debug, Clone)] -pub enum AcceptParams { - Static(QMediaType), - Dynamic(SmallVec<[QMediaType; 1]>) -} - macro_rules! accept_constructor { ($($name:ident ($check:ident): $str:expr, $t:expr, $s:expr $(; $k:expr => $v:expr)*,)+) => { $( - #[doc="An `Accept` header with the single media type for "] - #[doc=$str] #[doc=": "] - #[doc=$t] #[doc="/"] #[doc=$s] - #[doc=""] + #[doc="An `Accept` header with the single media type for"] + #[doc=concat!("**", $str, "**: ", "_", $t, "/", $s, "_")] #[allow(non_upper_case_globals)] pub const $name: Accept = Accept( - AcceptParams::Static(QMediaType(MediaType::$name, None)) + SmallVec::from_const([QMediaType(MediaType::$name, None)]) ); )+ }; @@ -111,7 +101,7 @@ impl Accept { /// ``` #[inline(always)] pub fn new>(items: T) -> Accept { - Accept(AcceptParams::Dynamic(items.into_collection())) + Accept(items.into_collection()) } // TODO: Implement this. @@ -211,10 +201,7 @@ impl Accept { /// ``` #[inline(always)] pub fn iter(&self) -> impl Iterator + '_ { - match self.0 { - AcceptParams::Static(ref val) => Either::Left(Some(val).into_iter()), - AcceptParams::Dynamic(ref vec) => Either::Right(vec.iter()) - } + self.0.iter() } /// Returns an iterator over all of the (bare) media types in `self`. Media @@ -249,7 +236,7 @@ impl Accept { impl> From for Accept { #[inline(always)] fn from(items: T) -> Accept { - Accept(AcceptParams::Dynamic(items.mapped(|item| item.into()))) + Accept(items.mapped(|item| item.into())) } } @@ -361,21 +348,6 @@ impl Deref for QMediaType { } } -impl Default for AcceptParams { - fn default() -> Self { - AcceptParams::Dynamic(SmallVec::new()) - } -} - -impl Extend for AcceptParams { - fn extend>(&mut self, iter: T) { - match self { - AcceptParams::Static(..) => panic!("can't add to static collection!"), - AcceptParams::Dynamic(ref mut v) => v.extend(iter) - } - } -} - #[cfg(test)] mod test { use crate::{Accept, MediaType}; diff --git a/core/http/src/lib.rs b/core/http/src/lib.rs index bdafb283..7ab89758 100644 --- a/core/http/src/lib.rs +++ b/core/http/src/lib.rs @@ -1,5 +1,3 @@ -#![recursion_limit="512"] - #![warn(rust_2018_idioms)] #![warn(missing_docs)]