Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ringmap"
edition = "2021"
version = "0.2.1"
version = "0.2.2"
documentation = "https://docs.rs/ringmap/"
repository = "https://github.com/indexmap-rs/ringmap"
license = "Apache-2.0 OR MIT"
Expand Down
5 changes: 5 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Releases

## 0.2.2 (2026-01-07)

- Added `map::Slice::split_at_checked` and `split_at_mut_checked`.
- Added `set::Slice::split_at_checked`.

## 0.2.1 (2025-11-20)

- Simplified a lot of internals using `hashbrown`'s new bucket API.
Expand Down
18 changes: 18 additions & 0 deletions src/map/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl<K, V> Slice<K, V> {
/// Divides one slice into two at an index.
///
/// ***Panics*** if `index > len`.
/// For a non-panicking alternative see [`split_at_checked`][Self::split_at_checked].
#[track_caller]
pub fn split_at(&self, index: usize) -> (&Self, &Self) {
let (first, second) = self.entries.split_at(index);
Expand All @@ -128,12 +129,29 @@ impl<K, V> Slice<K, V> {
/// Divides one mutable slice into two at an index.
///
/// ***Panics*** if `index > len`.
/// For a non-panicking alternative see [`split_at_mut_checked`][Self::split_at_mut_checked].
#[track_caller]
pub fn split_at_mut(&mut self, index: usize) -> (&mut Self, &mut Self) {
let (first, second) = self.entries.split_at_mut(index);
(Self::from_mut_slice(first), Self::from_mut_slice(second))
}

/// Divides one slice into two at an index.
///
/// Returns `None` if `index > len`.
pub fn split_at_checked(&self, index: usize) -> Option<(&Self, &Self)> {
let (first, second) = self.entries.split_at_checked(index)?;
Some((Self::from_slice(first), Self::from_slice(second)))
}

/// Divides one mutable slice into two at an index.
///
/// Returns `None` if `index > len`.
pub fn split_at_mut_checked(&mut self, index: usize) -> Option<(&mut Self, &mut Self)> {
let (first, second) = self.entries.split_at_mut_checked(index)?;
Some((Self::from_mut_slice(first), Self::from_mut_slice(second)))
}

/// 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)> {
Expand Down
9 changes: 9 additions & 0 deletions src/set/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,21 @@ impl<T> Slice<T> {
/// Divides one slice into two at an index.
///
/// ***Panics*** if `index > len`.
/// For a non-panicking alternative see [`split_at_checked`][Self::split_at_checked].
#[track_caller]
pub fn split_at(&self, index: usize) -> (&Self, &Self) {
let (first, second) = self.entries.split_at(index);
(Self::from_slice(first), Self::from_slice(second))
}

/// Divides one slice into two at an index.
///
/// Returns `None` if `index > len`.
pub fn split_at_checked(&self, index: usize) -> Option<(&Self, &Self)> {
let (first, second) = self.entries.split_at_checked(index)?;
Some((Self::from_slice(first), Self::from_slice(second)))
}

/// Returns the first value and the rest of the slice,
/// or `None` if it is empty.
pub fn split_first(&self) -> Option<(&T, &Self)> {
Expand Down