diff --git a/core/codegen/tests/route-format.rs b/core/codegen/tests/route-format.rs index 5140a27d..c0d927d7 100644 --- a/core/codegen/tests/route-format.rs +++ b/core/codegen/tests/route-format.rs @@ -89,10 +89,10 @@ fn test_custom_formats() { let client = Client::debug(rocket).unwrap(); - let foo_a = Accept::new(&[MediaType::new("application", "foo").into()]); + let foo_a = Accept::new([MediaType::new("application", "foo").into()]); let foo_ct = ContentType::new("application", "foo"); let bar_baz_ct = ContentType::new("bar", "baz"); - let bar_baz_a = Accept::new(&[MediaType::new("bar", "baz").into()]); + let bar_baz_a = Accept::new([MediaType::new("bar", "baz").into()]); let response = client.get("/").header(foo_a).dispatch(); assert_eq!(response.into_string().unwrap(), "get_foo"); diff --git a/core/http/src/ext.rs b/core/http/src/ext.rs index 7741d31c..71758980 100644 --- a/core/http/src/ext.rs +++ b/core/http/src/ext.rs @@ -46,35 +46,33 @@ impl IntoCollection for Vec { } } -macro_rules! impl_for_slice { - ($($size:tt)*) => ( - impl IntoCollection for &[T $($size)*] { - #[inline(always)] - fn into_collection>(self) -> SmallVec { - self.iter().cloned().collect() - } +impl IntoCollection for &[T] { + #[inline(always)] + fn into_collection>(self) -> SmallVec { + self.iter().cloned().collect() + } - #[inline] - fn mapped>(self, f: F) -> SmallVec - where F: FnMut(T) -> U - { - self.iter().cloned().map(f).collect() - } - } - ) + #[inline] + fn mapped>(self, f: F) -> SmallVec + where F: FnMut(T) -> U + { + self.iter().cloned().map(f).collect() + } } -impl_for_slice!(); -impl_for_slice!(; 1); -impl_for_slice!(; 2); -impl_for_slice!(; 3); -impl_for_slice!(; 4); -impl_for_slice!(; 5); -impl_for_slice!(; 6); -impl_for_slice!(; 7); -impl_for_slice!(; 8); -impl_for_slice!(; 9); -impl_for_slice!(; 10); +impl IntoCollection for [T; N] { + #[inline(always)] + fn into_collection>(self) -> SmallVec { + std::array::IntoIter::new(self).collect() + } + + #[inline] + fn mapped>(self, f: F) -> SmallVec + where F: FnMut(T) -> U + { + std::array::IntoIter::new(self).map(f).collect() + } +} use std::borrow::Cow; diff --git a/core/http/src/header/accept.rs b/core/http/src/header/accept.rs index a6082386..e133f113 100644 --- a/core/http/src/header/accept.rs +++ b/core/http/src/header/accept.rs @@ -85,9 +85,10 @@ macro_rules! accept_constructor { impl Accept { /// Constructs a new `Accept` header from one or more media types. /// - /// The `items` parameter may be of type `QMediaType`, `&[QMediaType]`, or - /// `Vec`. To prevent additional allocations, prefer to provide - /// inputs of type `QMediaType` and `Vec`. + /// The `items` parameter may be of type `QMediaType`, `[QMediaType]`, + /// `&[QMediaType]` or `Vec`. To prevent additional allocations, + /// prefer to provide inputs of type `QMediaType`, `[QMediaType]`, or + /// `Vec`. /// /// # Example /// @@ -100,8 +101,8 @@ impl Accept { /// let accept = Accept::new(json_then_html); /// assert_eq!(accept.preferred().media_type(), &MediaType::JSON); /// - /// // Construct an `Accept` via an `&[QMediaType]`. - /// let accept = Accept::new(&[MediaType::JSON.into(), MediaType::HTML.into()]); + /// // Construct an `Accept` via an `[QMediaType]`. + /// let accept = Accept::new([MediaType::JSON.into(), MediaType::HTML.into()]); /// assert_eq!(accept.preferred().media_type(), &MediaType::JSON); /// /// // Construct an `Accept` via a `QMediaType`.