Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.21.0 #52

Merged
merged 2 commits into from
Nov 27, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.21.0

- Use state pattern for `EntryRef`

## 0.20.0

- Add dynamic `SkipMap`s
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "skl"
version = "0.20.2"
version = "0.21.0"
edition = "2021"
rust-version = "1.81.0"
repository = "https://github.com/al8n/skl"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@

```toml
[dependencies]
skl = "0.20"
skl = "0.21"
```

- Enable memory map backend

```toml
[dependencies]
skl = { version = "0.20", features = ["memmap"] }
skl = { version = "0.21", features = ["memmap"] }
```

## Features
Expand Down
66 changes: 62 additions & 4 deletions src/dynamic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(single_use_lifetimes)]

mod list;

/// Dynamic key-value `SkipMap` implementation with multiple versions support.
Expand All @@ -13,12 +11,72 @@ pub use builder::Builder;

/// Iterators for the skipmaps.
pub mod iter {
pub use super::list::iterator::{Iter, IterAll};
pub use super::list::iterator::Iter;
}

/// Entry references for the skipmaps.
pub mod entry {
pub use super::list::{EntryRef, VersionedEntryRef};
pub use super::list::EntryRef;
}

pub use dbutils::equivalentor::*;

/// Value that can be converted from a byte slice.
pub trait Value<'a>: sealed::Sealed<'a> {}

impl<'a, T> Value<'a> for T where T: sealed::Sealed<'a> {}

mod sealed {
pub trait Sealed<'a> {
type Ref;

fn as_ref(&self) -> Self::Ref;

fn from_value_bytes(src: Option<&'a [u8]>) -> Self
where
Self: 'a;

fn is_removed(&self) -> bool;
}

impl<'a> Sealed<'a> for Option<&'a [u8]> {
type Ref = Option<&'a [u8]>;

#[inline]
fn as_ref(&self) -> Self::Ref {
self.as_ref().copied()
}

#[inline]
fn from_value_bytes(src: Option<&'a [u8]>) -> Self {
src
}

#[inline]
fn is_removed(&self) -> bool {
self.is_none()
}
}

impl<'a> Sealed<'a> for &'a [u8] {
type Ref = Self;

#[inline]
fn as_ref(&self) -> Self::Ref {
self
}

#[inline]
fn from_value_bytes(src: Option<&'a [u8]>) -> Self {
match src {
Some(v) => v,
None => panic!("cannot convert None to Value"),
}
}

#[inline]
fn is_removed(&self) -> bool {
false
}
}
}
Loading
Loading