From 0937707fa11d08eb8610dbd8927476221c5b082c Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 6 May 2022 18:30:46 -0700 Subject: [PATCH 1/4] Use first-class patterns for split_first/last --- src/map/slice.rs | 8 ++++---- src/set/slice.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/map/slice.rs b/src/map/slice.rs index 07c6705a..4b2029db 100644 --- a/src/map/slice.rs +++ b/src/map/slice.rs @@ -130,7 +130,7 @@ impl Slice { /// Returns the first key-value pair and the rest of the slice, /// or `None` if it is empty. pub fn split_first(&self) -> Option<((&K, &V), &Self)> { - if let Some((first, rest)) = self.entries.split_first() { + if let [first, rest @ ..] = &self.entries { Some((first.refs(), Self::from_slice(rest))) } else { None @@ -140,7 +140,7 @@ impl Slice { /// Returns the first key-value pair and the rest of the slice, /// with mutable access to the value, or `None` if it is empty. pub fn split_first_mut(&mut self) -> Option<((&K, &mut V), &mut Self)> { - if let Some((first, rest)) = self.entries.split_first_mut() { + if let [first, rest @ ..] = &mut self.entries { Some((first.ref_mut(), Self::from_mut_slice(rest))) } else { None @@ -150,7 +150,7 @@ impl Slice { /// Returns the last key-value pair and the rest of the slice, /// or `None` if it is empty. pub fn split_last(&self) -> Option<((&K, &V), &Self)> { - if let Some((last, rest)) = self.entries.split_last() { + if let [rest @ .., last] = &self.entries { Some((last.refs(), Self::from_slice(rest))) } else { None @@ -160,7 +160,7 @@ impl Slice { /// Returns the last key-value pair and the rest of the slice, /// with mutable access to the value, or `None` if it is empty. pub fn split_last_mut(&mut self) -> Option<((&K, &mut V), &mut Self)> { - if let Some((last, rest)) = self.entries.split_last_mut() { + if let [rest @ .., last] = &mut self.entries { Some((last.ref_mut(), Self::from_mut_slice(rest))) } else { None diff --git a/src/set/slice.rs b/src/set/slice.rs index dd317ebd..0924e8b9 100644 --- a/src/set/slice.rs +++ b/src/set/slice.rs @@ -88,7 +88,7 @@ impl Slice { /// Returns the first value and the rest of the slice, /// or `None` if it is empty. pub fn split_first(&self) -> Option<(&T, &Self)> { - if let Some((first, rest)) = self.entries.split_first() { + if let [first, rest @ ..] = &self.entries { Some((&first.key, Self::from_slice(rest))) } else { None @@ -98,7 +98,7 @@ impl Slice { /// Returns the last value and the rest of the slice, /// or `None` if it is empty. pub fn split_last(&self) -> Option<(&T, &Self)> { - if let Some((last, rest)) = self.entries.split_last() { + if let [rest @ .., last] = &self.entries { Some((&last.key, Self::from_slice(rest))) } else { None From cda1a0b5c947330ece313fe3ab2cc1fe906f1ed4 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 6 May 2022 18:30:56 -0700 Subject: [PATCH 2/4] cargo fmt --- src/map/core.rs | 3 ++- src/serde_seq.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/map/core.rs b/src/map/core.rs index 50ebebea..0bc54621 100644 --- a/src/map/core.rs +++ b/src/map/core.rs @@ -204,7 +204,8 @@ impl IndexMapCore { /// Shrink the capacity of the map with a lower bound pub(crate) fn shrink_to(&mut self, min_capacity: usize) { - self.indices.shrink_to(min_capacity, get_hash(&self.entries)); + self.indices + .shrink_to(min_capacity, get_hash(&self.entries)); self.entries.shrink_to(min_capacity); } diff --git a/src/serde_seq.rs b/src/serde_seq.rs index b8bd8203..c3ab6623 100644 --- a/src/serde_seq.rs +++ b/src/serde_seq.rs @@ -27,9 +27,9 @@ use core::fmt::{self, Formatter}; use core::hash::{BuildHasher, Hash}; use core::marker::PhantomData; -use crate::IndexMap; use crate::map::Slice as MapSlice; use crate::set::Slice as SetSlice; +use crate::IndexMap; /// Serializes a `map::Slice` as an ordered sequence. /// From adb8c1012e40261bf87084f8df51871e47d0affc Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 6 May 2022 18:37:19 -0700 Subject: [PATCH 3/4] typo fix --- src/serde_seq.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/serde_seq.rs b/src/serde_seq.rs index c3ab6623..e8d4c43c 100644 --- a/src/serde_seq.rs +++ b/src/serde_seq.rs @@ -34,7 +34,7 @@ use crate::IndexMap; /// Serializes a `map::Slice` as an ordered sequence. /// /// This behaves like [`crate::serde_seq`] for `IndexMap`, serializing a sequence -/// of `(key, value)` pairs, rather than as a map that might not preserver order. +/// of `(key, value)` pairs, rather than as a map that might not preserve order. /// /// Requires crate feature `"serde"` or `"serde-1"` impl Serialize for MapSlice From ebe2f2993dec26ce634711f87ed70e8d2f9fc46c Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 6 May 2022 18:38:42 -0700 Subject: [PATCH 4/4] Remove outdated references to serde-1 --- src/serde_seq.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/serde_seq.rs b/src/serde_seq.rs index e8d4c43c..618e871f 100644 --- a/src/serde_seq.rs +++ b/src/serde_seq.rs @@ -36,7 +36,7 @@ use crate::IndexMap; /// This behaves like [`crate::serde_seq`] for `IndexMap`, serializing a sequence /// of `(key, value)` pairs, rather than as a map that might not preserve order. /// -/// Requires crate feature `"serde"` or `"serde-1"` +/// Requires crate feature `"serde"` impl Serialize for MapSlice where K: Serialize, @@ -52,7 +52,7 @@ where /// Serializes a `set::Slice` as an ordered sequence. /// -/// Requires crate feature `"serde"` or `"serde-1"` +/// Requires crate feature `"serde"` impl Serialize for SetSlice where T: Serialize,