Skip to content

Commit

Permalink
Update clippy and docs
Browse files Browse the repository at this point in the history
Applies lifetime fixes flagged by clippy and fixes to doc comments.

Signed-off-by: Fintan Halpenny <[email protected]>
X-Clacks-Overhead: GNU Terry Pratchett
  • Loading branch information
FintanH committed Dec 17, 2024
1 parent 4b255e7 commit 6d027dc
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'a, T> Iterator for Iter<'a, T> {
}
}

impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
impl<T> DoubleEndedIterator for Iter<'_, T> {
fn next_back(&mut self) -> Option<Self::Item> {
if let Some((last, rest)) = self.tail.split_last() {
self.tail = rest;
Expand All @@ -180,21 +180,21 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
}
}

impl<'a, T> ExactSizeIterator for Iter<'a, T> {
impl<T> ExactSizeIterator for Iter<'_, T> {
fn len(&self) -> usize {
self.tail.len() + self.head.map_or(0, |_| 1)
}
}

impl<'a, T> core::iter::FusedIterator for Iter<'a, T> {}
impl<T> core::iter::FusedIterator for Iter<'_, T> {}

impl<T> NonEmpty<T> {
/// Alias for [`NonEmpty::singleton`].
pub const fn new(e: T) -> Self {
Self::singleton(e)
}

/// Converts from &NonEmpty<T> to NonEmpty<&T>.
/// Converts from `&NonEmpty<T>` to `NonEmpty<&T>`.
pub fn as_ref(&self) -> NonEmpty<&T> {
NonEmpty {
head: &self.head,
Expand Down Expand Up @@ -696,7 +696,7 @@ impl<T> NonEmpty<T> {
/// # Examples
///
/// Looks up a series of four elements. The first is found, with a uniquely determined
/// position; the second and third are not found; the fourth could match any position in [1,4].
/// position; the second and third are not found; the fourth could match any position in `[1,4]`.
///
/// ```
/// use nonempty::NonEmpty;
Expand Down Expand Up @@ -827,9 +827,9 @@ impl<T> NonEmpty<T> {
/// let non_empty = NonEmpty::from(((2, 1), vec![(2, -34), (4, 42), (0, 76), (1, 4), (3, 5)]));
/// assert_eq!(non_empty.maximum_by(|(k, _), (l, _)| k.cmp(l)), &(4, 42));
/// ```
pub fn maximum_by<'a, F>(&'a self, mut compare: F) -> &T
pub fn maximum_by<F>(&self, mut compare: F) -> &T
where
F: FnMut(&'a T, &'a T) -> Ordering,
F: FnMut(&T, &T) -> Ordering,
{
let mut max = &self.head;
for i in self.tail.iter() {
Expand All @@ -855,9 +855,9 @@ impl<T> NonEmpty<T> {
/// let non_empty = NonEmpty::from(((2, 1), vec![(2, -34), (4, 42), (0, 76), (1, 4), (3, 5)]));
/// assert_eq!(non_empty.minimum_by(|(k, _), (l, _)| k.cmp(l)), &(0, 76));
/// ```
pub fn minimum_by<'a, F>(&'a self, mut compare: F) -> &T
pub fn minimum_by<F>(&self, mut compare: F) -> &T
where
F: FnMut(&'a T, &'a T) -> Ordering,
F: FnMut(&T, &T) -> Ordering,
{
self.maximum_by(|a, b| compare(a, b).reverse())
}
Expand All @@ -872,16 +872,16 @@ impl<T> NonEmpty<T> {
/// use nonempty::NonEmpty;
///
/// let non_empty = NonEmpty::new((0, 42));
/// assert_eq!(non_empty.maximum_by_key(|(k, _)| k), &(0, 42));
/// assert_eq!(non_empty.maximum_by_key(|(k, _)| *k), &(0, 42));
///
/// let non_empty = NonEmpty::from(((2, 1), vec![(2, -34), (4, 42), (0, 76), (1, 4), (3, 5)]));
/// assert_eq!(non_empty.maximum_by_key(|(k, _)| k), &(4, 42));
/// assert_eq!(non_empty.maximum_by_key(|(k, _)| *k), &(4, 42));
/// assert_eq!(non_empty.maximum_by_key(|(k, _)| -k), &(0, 76));
/// ```
pub fn maximum_by_key<'a, U, F>(&'a self, mut f: F) -> &T
pub fn maximum_by_key<U, F>(&self, mut f: F) -> &T
where
U: Ord,
F: FnMut(&'a T) -> U,
F: FnMut(&T) -> U,
{
self.maximum_by(|i, j| f(i).cmp(&f(j)))
}
Expand All @@ -896,16 +896,16 @@ impl<T> NonEmpty<T> {
/// use nonempty::NonEmpty;
///
/// let non_empty = NonEmpty::new((0, 42));
/// assert_eq!(non_empty.minimum_by_key(|(k, _)| k), &(0, 42));
/// assert_eq!(non_empty.minimum_by_key(|(k, _)| *k), &(0, 42));
///
/// let non_empty = NonEmpty::from(((2, 1), vec![(2, -34), (4, 42), (0, 76), (1, 4), (3, 5)]));
/// assert_eq!(non_empty.minimum_by_key(|(k, _)| k), &(0, 76));
/// assert_eq!(non_empty.minimum_by_key(|(k, _)| *k), &(0, 76));
/// assert_eq!(non_empty.minimum_by_key(|(k, _)| -k), &(4, 42));
/// ```
pub fn minimum_by_key<'a, U, F>(&'a self, mut f: F) -> &T
pub fn minimum_by_key<U, F>(&self, mut f: F) -> &T
where
U: Ord,
F: FnMut(&'a T) -> U,
F: FnMut(&T) -> U,
{
self.minimum_by(|i, j| f(i).cmp(&f(j)))
}
Expand Down

0 comments on commit 6d027dc

Please sign in to comment.