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
15 changes: 1 addition & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,7 @@ jobs:
- name: Install cargo-hack
uses: taiki-e/install-action@cargo-hack
- run: cargo hack build --rust-version

no-std:
strategy:
matrix:
rust:
# This is the minimum supported Rust version for "no_std"
- 1.36.0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
- run: rustup target add thumbv7m-none-eabi
- run: cargo build --no-default-features --target thumbv7m-none-eabi
- run: cargo hack build --rust-version --no-default-features --target thumbv7m-none-eabi

miri:
runs-on: ubuntu-latest
Expand Down
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "slab"
version = "0.4.9"
authors = ["Carl Lerche <me@carllerche.com>"]
edition = "2018"
rust-version = "1.31"
rust-version = "1.46"
license = "MIT"
description = "Pre-allocated storage for a uniform data type"
repository = "https://github.com/tokio-rs/slab"
Expand All @@ -21,13 +21,9 @@ exclude = ["/.*"]
std = []
default = ["std"]

[build-dependencies]
autocfg = "1"

[dependencies]
serde = { version = "1.0.95", optional = true, default-features = false, features = ["alloc"] }

[dev-dependencies]
rustversion = "1"
serde = { version = "1", features = ["derive"] }
serde_test = "1"
27 changes: 0 additions & 27 deletions build.rs

This file was deleted.

30 changes: 5 additions & 25 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,36 +242,19 @@ impl<T> Slab<T> {
/// The function does not allocate and the returned slab will have no
/// capacity until `insert` is called or capacity is explicitly reserved.
///
/// This is `const fn` on Rust 1.39+.
///
/// # Examples
///
/// ```
/// # use slab::*;
/// let slab: Slab<i32> = Slab::new();
/// ```
#[cfg(not(slab_no_const_vec_new))]
pub const fn new() -> Self {
Self {
entries: Vec::new(),
next: 0,
len: 0,
}
}
/// Construct a new, empty `Slab`.
///
/// The function does not allocate and the returned slab will have no
/// capacity until `insert` is called or capacity is explicitly reserved.
///
/// This is `const fn` on Rust 1.39+.
#[cfg(slab_no_const_vec_new)]
pub fn new() -> Self {
Self {
entries: Vec::new(),
next: 0,
len: 0,
}
}

/// Construct a new, empty `Slab` with the specified capacity.
///
Expand Down Expand Up @@ -929,7 +912,7 @@ impl<T> Slab<T> {
/// slab.key_of(bad); // this will panic
/// unreachable!();
/// ```
#[cfg_attr(not(slab_no_track_caller), track_caller)]
#[track_caller]
pub fn key_of(&self, present_element: &T) -> usize {
let element_ptr = present_element as *const T as usize;
let base_ptr = self.entries.as_ptr() as usize;
Expand Down Expand Up @@ -1098,7 +1081,7 @@ impl<T> Slab<T> {
/// assert_eq!(slab.remove(hello), "hello");
/// assert!(!slab.contains(hello));
/// ```
#[cfg_attr(not(slab_no_track_caller), track_caller)]
#[track_caller]
pub fn remove(&mut self, key: usize) -> T {
self.try_remove(key).expect("invalid key")
}
Expand All @@ -1119,10 +1102,7 @@ impl<T> Slab<T> {
/// assert!(!slab.contains(hello));
/// ```
pub fn contains(&self, key: usize) -> bool {
match self.entries.get(key) {
Some(&Entry::Occupied(_)) => true,
_ => false,
}
matches!(self.entries.get(key), Some(&Entry::Occupied(_)))
}

/// Retain only the elements specified by the predicate.
Expand Down Expand Up @@ -1206,7 +1186,7 @@ impl<T> Slab<T> {
impl<T> ops::Index<usize> for Slab<T> {
type Output = T;

#[cfg_attr(not(slab_no_track_caller), track_caller)]
#[track_caller]
fn index(&self, key: usize) -> &T {
match self.entries.get(key) {
Some(Entry::Occupied(v)) => v,
Expand All @@ -1216,7 +1196,7 @@ impl<T> ops::Index<usize> for Slab<T> {
}

impl<T> ops::IndexMut<usize> for Slab<T> {
#[cfg_attr(not(slab_no_track_caller), track_caller)]
#[track_caller]
fn index_mut(&mut self, key: usize) -> &mut T {
match self.entries.get_mut(key) {
Some(&mut Entry::Occupied(ref mut v)) => v,
Expand Down
7 changes: 3 additions & 4 deletions tests/slab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,23 @@ fn reserve_exact_does_not_allocate_if_available() {
fn reserve_does_panic_with_capacity_overflow() {
let mut slab = Slab::with_capacity(10);
slab.insert(true);
slab.reserve(std::isize::MAX as usize);
slab.reserve(isize::MAX as usize);
}

#[test]
#[should_panic(expected = "capacity overflow")]
fn reserve_does_panic_with_capacity_overflow_bytes() {
let mut slab = Slab::with_capacity(10);
slab.insert(1u16);
slab.reserve((std::isize::MAX as usize) / 2);
slab.reserve((isize::MAX as usize) / 2);
}

#[test]
#[should_panic(expected = "capacity overflow")]
fn reserve_exact_does_panic_with_capacity_overflow() {
let mut slab = Slab::with_capacity(10);
slab.insert(true);
slab.reserve_exact(std::isize::MAX as usize);
slab.reserve_exact(isize::MAX as usize);
}

#[test]
Expand Down Expand Up @@ -705,7 +705,6 @@ fn try_remove() {
assert_eq!(slab.get(key), None);
}

#[rustversion::since(1.39)]
#[test]
fn const_new() {
static _SLAB: Slab<()> = Slab::new();
Expand Down