Skip to content

Commit 0937707

Browse files
committed
Use first-class patterns for split_first/last
1 parent 5ba716b commit 0937707

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/map/slice.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<K, V> Slice<K, V> {
130130
/// Returns the first key-value pair and the rest of the slice,
131131
/// or `None` if it is empty.
132132
pub fn split_first(&self) -> Option<((&K, &V), &Self)> {
133-
if let Some((first, rest)) = self.entries.split_first() {
133+
if let [first, rest @ ..] = &self.entries {
134134
Some((first.refs(), Self::from_slice(rest)))
135135
} else {
136136
None
@@ -140,7 +140,7 @@ impl<K, V> Slice<K, V> {
140140
/// Returns the first key-value pair and the rest of the slice,
141141
/// with mutable access to the value, or `None` if it is empty.
142142
pub fn split_first_mut(&mut self) -> Option<((&K, &mut V), &mut Self)> {
143-
if let Some((first, rest)) = self.entries.split_first_mut() {
143+
if let [first, rest @ ..] = &mut self.entries {
144144
Some((first.ref_mut(), Self::from_mut_slice(rest)))
145145
} else {
146146
None
@@ -150,7 +150,7 @@ impl<K, V> Slice<K, V> {
150150
/// Returns the last key-value pair and the rest of the slice,
151151
/// or `None` if it is empty.
152152
pub fn split_last(&self) -> Option<((&K, &V), &Self)> {
153-
if let Some((last, rest)) = self.entries.split_last() {
153+
if let [rest @ .., last] = &self.entries {
154154
Some((last.refs(), Self::from_slice(rest)))
155155
} else {
156156
None
@@ -160,7 +160,7 @@ impl<K, V> Slice<K, V> {
160160
/// Returns the last key-value pair and the rest of the slice,
161161
/// with mutable access to the value, or `None` if it is empty.
162162
pub fn split_last_mut(&mut self) -> Option<((&K, &mut V), &mut Self)> {
163-
if let Some((last, rest)) = self.entries.split_last_mut() {
163+
if let [rest @ .., last] = &mut self.entries {
164164
Some((last.ref_mut(), Self::from_mut_slice(rest)))
165165
} else {
166166
None

src/set/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<T> Slice<T> {
8888
/// Returns the first value and the rest of the slice,
8989
/// or `None` if it is empty.
9090
pub fn split_first(&self) -> Option<(&T, &Self)> {
91-
if let Some((first, rest)) = self.entries.split_first() {
91+
if let [first, rest @ ..] = &self.entries {
9292
Some((&first.key, Self::from_slice(rest)))
9393
} else {
9494
None
@@ -98,7 +98,7 @@ impl<T> Slice<T> {
9898
/// Returns the last value and the rest of the slice,
9999
/// or `None` if it is empty.
100100
pub fn split_last(&self) -> Option<(&T, &Self)> {
101-
if let Some((last, rest)) = self.entries.split_last() {
101+
if let [rest @ .., last] = &self.entries {
102102
Some((&last.key, Self::from_slice(rest)))
103103
} else {
104104
None

0 commit comments

Comments
 (0)