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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.1.2 (Dec 18, 2025)

* Fix bug in `StrongSlab`
* Update documentation

# 0.1.1 (March 08, 2024)

* Update documentation
Expand Down
39 changes: 33 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
[package]

name = "generic_slab"
# When releasing to crates.io:
# - Update version number
# - README.md
# - Update CHANGELOG.md
# - Create git tag
version = "0.1.1"
authors = [ "Bergmann89 <info@bergmann89.de>", "Carl Lerche <me@carllerche.com>" ]
edition = "2018"
Expand All @@ -17,6 +11,9 @@ keywords = [ "slab", "allocator", "no_std", "fixed", "generic" ]
categories = [ "memory-management", "data-structures", "no-std" ]
exclude = [ "/.*" ]

[package.metadata.docs.rs]
all-features = true

[features]
std = [ ]
default = [ "std" ]
Expand All @@ -33,3 +30,33 @@ arrayvec = "0.7.4"
rustversion = "1"
serde = { version = "1", features = [ "derive" ] }
serde_test = "1"


[lints.rust]
future_incompatible = { level = "warn", priority = -1}
incomplete_features = "allow"
missing_debug_implementations = { level = "warn", priority = -1}
missing_docs = { level = "warn", priority = -1}
nonstandard_style = { level = "warn", priority = -1}
rust_2018_idioms = { level = "warn", priority = -1}
rust_2021_compatibility = { level = "warn", priority = -1}
unexpected_cfgs = "allow"
unreachable_pub = { level = "warn", priority = -1}
unused = { level = "warn", priority = -1}

[lints.clippy]
cast_possible_truncation = "warn"
default_trait_access = "allow"
explicit_iter_loop = "allow"
match_same_arms = "allow"
match_wildcard_for_single_variants = "allow"
missing_fields_in_debug = "allow"
missing_panics_doc = "allow"
module_name_repetitions = "allow"
needless_pass_by_value = "allow"
no_effect_underscore_binding = "allow"
pedantic = { level = "warn", priority = -1}
similar_names = "allow"
single_match_else = "allow"
struct_field_names = "allow"
uninlined_format_args = "allow"
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

`generic_slab` is a fork of [`slab`](https://github.com/tokio-rs/slab) that provides more control over the key and storage types. Using a generic approach you can for example implement strong typed keys that must fit the data type stored in the slab, or you can use a fixed size array as backing storage for the slab data.

[![Crates.io][crates-badge]][crates-url]
[![Build Status][ci-badge]][ci-url]

[crates-badge]: https://img.shields.io/crates/v/generic_slab
[crates-url]: https://crates.io/crates/generic_slab
[ci-badge]: https://img.shields.io/github/actions/workflow/status/Bergmann89/generic_slab/ci.yml?branch=master
[ci-url]: https://github.com/Bergmann89/generic_slab/actions
<a href="https://github.com/Bergmann89/generic_slab/blob/master/LICENSE"><img src="https://img.shields.io/crates/l/generic_slab" alt="Crates.io License"></a> <a href="https://crates.io/crates/generic_slab"><img src="https://img.shields.io/crates/v/generic_slab" alt="Crates.io Version"></a> <a href="https://crates.io/crates/generic_slab"><img src="https://img.shields.io/crates/d/generic_slab" alt="Crates.io Total Downloads"></a> <a href="https://docs.rs/generic_slab"><img src="https://img.shields.io/docsrs/generic_slab" alt="docs.rs"></a> <a href="https://github.com/Bergmann89/generic_slab/actions/workflows/ci.yml"><img src="https://github.com/Bergmann89/generic_slab/actions/workflows/ci.yml/badge.svg" alt="Github CI"></a> <a href="https://deps.rs/repo/github/Bergmann89/generic_slab"><img src="https://deps.rs/repo/github/Bergmann89/generic_slab/status.svg" alt="Dependency Status"></a>

[Documentation](https://docs.rs/generic_slab)

Expand Down
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Build script that sets some flags depending on the used rust version.

fn main() {
let cfg = match autocfg::AutoCfg::new() {
Ok(cfg) => cfg,
Expand Down
2 changes: 1 addition & 1 deletion src/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ where

#[inline]
fn clear(&mut self) {
Vec::clear(self)
Vec::clear(self);
}

#[inline]
Expand Down
7 changes: 5 additions & 2 deletions src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ where
/// # use generic_slab::*;
/// let slab: Slab<i32> = Slab::new();
/// ```
#[must_use]
pub fn new() -> Self {
Self::from_entries(TEntries::default())
}
Expand All @@ -130,7 +131,7 @@ where
TKey: Key<T>,
TEntries: Entries<T, TKey>,
{
/// Construct a new, empty `Slab` using the provided `entries``.
/// Construct a new, empty `Slab` using the provided `entries`.
///
/// Before the slab is created the passed `entries` will be cleared.
///
Expand Down Expand Up @@ -1522,6 +1523,7 @@ where
/// // ...but this may make the slab reallocate
/// slab.insert(11);
/// ```
#[must_use]
pub fn with_capacity(capacity: usize) -> Self {
Self::from_entries(TEntries::with_capacity(capacity))
}
Expand Down Expand Up @@ -1773,6 +1775,7 @@ where
TEntries: Entries<T, TKey>,
{
/// Get the key of this vacant entry.
#[must_use]
pub fn key(&self) -> TKey {
self.slab.vacant_key_at(self.index)
}
Expand All @@ -1788,7 +1791,7 @@ where
}
}

impl<'a, T, TKey, TEntries> Debug for GenericVacantEntry<'a, T, TKey, TEntries>
impl<T, TKey, TEntries> Debug for GenericVacantEntry<'_, T, TKey, TEntries>
where
TKey: Key<T>,
{
Expand Down
24 changes: 22 additions & 2 deletions src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<T> Key<T> for Handle<T> {
Self {
id: cx.id,
index,
count: data.map(Clone::clone).unwrap_or_default(),
count: data.cloned().unwrap_or_default(),
marker: PhantomData,
}
}
Expand All @@ -115,7 +115,7 @@ impl<T> Key<T> for Handle<T> {
fn convert_into_vacant(cx: &Self::Context, data: Self::OccupiedData) -> Self::VacantData {
let _cx = cx;

data
data.overflowing_add(1).0
}

#[inline]
Expand Down Expand Up @@ -147,3 +147,23 @@ impl Default for Context {
}

static NEXT_ID: AtomicUsize = AtomicUsize::new(0);

#[cfg(test)]
mod tests {
use crate::StrongSlab;

#[test]
fn strong_slab() {
let mut slab = StrongSlab::new();

let handle0 = slab.insert("hello");
assert_eq!(handle0.index, 0);
assert_eq!(handle0.count, 0);
slab.remove(handle0);

let handle1 = slab.insert("world");
assert!(slab.get(handle0).is_none());
assert_eq!(handle1.index, 0);
assert_eq!(handle1.count, 1);
}
}
Loading