From a1416317ea81bdf585b2bf604b33cce376cf5969 Mon Sep 17 00:00:00 2001 From: Gwen Lg Date: Sun, 16 Jun 2024 15:03:41 +0200 Subject: [PATCH] enable clippy::missing_inline_in_public_items lint and mark public function as `inline` --- src/from.rs | 1 + src/into.rs | 11 ++++++++--- src/lib.rs | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/from.rs b/src/from.rs index db9e861..c6b78c4 100644 --- a/src/from.rs +++ b/src/from.rs @@ -57,6 +57,7 @@ impl FromIteratorFixed for [T; N] { /// let a: [i32; 3] = two_four_six.collect(); /// assert_eq!(a, [2, 4, 6]); /// ``` + #[inline] fn from_iter_fixed>(iter_fixed: IteratorFixed) -> Self { let IteratorFixed { inner: mut it } = iter_fixed; // We know that it will yield N elements due to it originating from an IteratorFixed diff --git a/src/into.rs b/src/into.rs index 31f3c78..d5f0d16 100644 --- a/src/into.rs +++ b/src/into.rs @@ -35,7 +35,7 @@ pub unsafe trait IntoIteratorFixed { // IteratorFixed implements IntoIteratorFixed unsafe impl IntoIteratorFixed for IteratorFixed where - IteratorFixed: IntoIterator, + Self: IntoIterator, { type Item = I::Item; type IntoIter = I; @@ -51,6 +51,7 @@ where /// /// assert_eq!(zipped, [(1, 1), (2, 1)]); /// ``` + #[inline] fn into_iter_fixed(self) -> IteratorFixed { self } @@ -71,6 +72,7 @@ unsafe impl IntoIteratorFixed for [T; N] { /// let a: [i32; 3] = two_four_six.collect(); /// assert_eq!(a, [2, 4, 6]); /// ``` + #[inline] fn into_iter_fixed(self) -> IteratorFixed, N> { // Safety: array::IntoIter::new([T; N]) always yields N elements unsafe { IteratorFixed::from_iter(<[T; N] as IntoIterator>::into_iter(self)) } @@ -93,6 +95,7 @@ unsafe impl<'a, T, const N: usize> IntoIteratorFixed for &'a [T; N] { /// } /// assert_eq!(double(&[1, 2, 3]), [2, 4, 6]); /// ``` + #[inline] fn into_iter_fixed(self) -> IteratorFixed { // Safety: [T; N]::iter always yields N elements unsafe { IteratorFixed::from_iter(self.iter()) } @@ -123,6 +126,7 @@ unsafe impl<'a, T, const N: usize> IntoIteratorFixed for &'a mut [T; N] { /// assert_eq!(double(&mut a), [1, 2, 3]); /// assert_eq!(a, [2, 4, 6]); /// ``` + #[inline] fn into_iter_fixed(self) -> IteratorFixed { // Safety: [T; N]::iter always yields N elements unsafe { IteratorFixed::from_iter(self.iter_mut()) } @@ -131,7 +135,7 @@ unsafe impl<'a, T, const N: usize> IntoIteratorFixed for &'a mut [T; N] { unsafe impl IntoIteratorFixed for iter::Repeat { type Item = T; - type IntoIter = iter::Take>; + type IntoIter = iter::Take; /// Creates a fixed size iterator from an [`core::iter::Repeat`] /// @@ -145,7 +149,8 @@ unsafe impl IntoIteratorFixed for iter::Repeat { /// let a: [i32; 3] = one_one_one.collect(); /// assert_eq!(a, [1, 1, 1]); /// ``` - fn into_iter_fixed(self) -> IteratorFixed>, N> { + #[inline] + fn into_iter_fixed(self) -> IteratorFixed, N> { // Safety: iter::repeat(_).take(N) always yields N elements unsafe { IteratorFixed::from_iter(self.take(N)) } } diff --git a/src/lib.rs b/src/lib.rs index eccce1c..ab1b0f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ // enable additionnal lints #![warn(clippy::doc_markdown)] #![warn(clippy::ignored_unit_patterns)] +#![warn(clippy::missing_inline_in_public_items)] #![warn(clippy::use_self)] use core::iter; @@ -58,6 +59,7 @@ pub struct IteratorFixed { /// /// assert_eq!(zero_two_four, [0, 2, 4]); /// ``` +#[inline] pub fn from_fn<'a, F, T: 'a, const N: usize>( mut f: F, ) -> IteratorFixed + 'a, N> @@ -78,6 +80,7 @@ where /// Caller has to guarantee that the given iterator will yield exactly N elements /// // TODO: Would it be ok if it generated more elements? + #[inline] pub unsafe fn from_iter>(i: II) -> Self { Self { inner: i.into_iter(), @@ -85,6 +88,7 @@ where } /// See [`core::iter::Iterator::map`] + #[inline] pub fn map::Item) -> U>( self, p: F, @@ -95,6 +99,7 @@ where } /// See [`core::iter::Iterator::inspect`] + #[inline] pub fn inspect::Item)>( self, p: F, @@ -107,6 +112,7 @@ where // TODO: what should happen when SKIP > N? /// See [`core::iter::Iterator::skip`] #[cfg(feature = "nightly_features")] + #[inline] pub fn skip( self, ) -> IteratorFixed, { sub_or_zero(N, SKIP) }> { @@ -117,6 +123,7 @@ where /// See [`core::iter::Iterator::step_by`] #[cfg(feature = "nightly_features")] + #[inline] pub fn step_by( self, ) -> IteratorFixed, { ceiling_div(N, STEP) }> { @@ -127,6 +134,7 @@ where /// See [`core::iter::Iterator::chain`] #[cfg(feature = "nightly_features")] + #[inline] pub fn chain( self, other: IIF, @@ -140,6 +148,7 @@ where } /// See [`core::iter::Iterator::enumerate`] + #[inline] pub fn enumerate(self) -> IteratorFixed, N> { IteratorFixed { inner: self.inner.enumerate(), @@ -148,6 +157,7 @@ where /// See [`core::iter::Iterator::take`] #[cfg(feature = "nightly_features")] + #[inline] pub fn take( self, ) -> IteratorFixed, { min(TAKE, N) }> { @@ -157,6 +167,7 @@ where } /// See [`core::iter::Iterator::zip`] + #[inline] pub fn zip( self, other: IIF, @@ -181,6 +192,7 @@ where */ /// See [`core::iter::Iterator::rev`] + #[inline] pub fn rev(self) -> IteratorFixed, N> where I: iter::DoubleEndedIterator, @@ -191,6 +203,7 @@ where } #[cfg(feature = "nightly_features")] + #[inline] pub fn flatten( self, ) -> IteratorFixed, { M * N }> @@ -207,6 +220,7 @@ where } #[cfg(feature = "nightly_features")] + #[inline] pub fn flat_map( self, mut f: F, @@ -234,6 +248,7 @@ where /// let a: [i32; 3] = two_four_six.collect(); /// assert_eq!(a, [2, 4, 6]); /// ``` + #[inline] pub fn collect>(self) -> U { U::from_iter_fixed(self) } @@ -244,6 +259,7 @@ where I: Iterator, { /// See [`core::iter::Iterator::copied`] + #[inline] pub fn copied(self) -> IteratorFixed, N> where T: Copy, @@ -254,6 +270,7 @@ where } /// See [`core::iter::Iterator::cloned`] + #[inline] pub fn cloned(self) -> IteratorFixed, N> where T: Clone, @@ -271,6 +288,7 @@ impl, const N: usize> IntoIterator for IteratorFixed I { self.inner }