Skip to content

Commit

Permalink
bumpup among version
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Sep 14, 2024
1 parent 6a88769 commit e5e09d2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test-swmr = ["std"]
test-swmr-generic = ["std"]

[dependencies]
among = { version = "0.1", default-features = false }
among = { version = "0.1", default-features = false, features = ["either"] }
bitflags = { version = "1", default-features = false }
dbutils = { version = "0.3", default-features = false, features = ["crc32fast"] }
rarena-allocator = { version = "0.2", default-features = false, features = ["memmap"] }
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

use core::{borrow::Borrow, cmp, marker::PhantomData, mem, slice};

#[doc(inline)]
pub use among;
use among::Among;
use crossbeam_skiplist::SkipSet;
use error::Error;
Expand Down
51 changes: 15 additions & 36 deletions src/swmr/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ pub struct Pointer<K, V> {
_m: PhantomData<(K, V)>,
}

impl<K, V> Clone for Pointer<K, V> {
fn clone(&self) -> Self {
*self
}
}

impl<K, V> Copy for Pointer<K, V> {}

impl<K: Type, V> PartialEq for Pointer<K, V> {
fn eq(&self, other: &Self) -> bool {
self.as_key_slice() == other.as_key_slice()
Expand Down Expand Up @@ -669,7 +661,7 @@ where
opts: Options,
open_options: OpenOptions,
) -> Result<Self, Error> {
Self::map_mut_with_path_builder::<_, ()>(|| Ok(path.as_ref().to_path_buf()), opts, open_options)
Self::map_mut_with_path_builder::<_, ()>(|| dummy_path_builder(path), opts, open_options)
.map_err(|e| e.unwrap_right())
}

Expand Down Expand Up @@ -730,7 +722,7 @@ where
path: P,
opts: Options,
) -> Result<GenericWalReader<K, V>, Error> {
Self::map_with_path_builder::<_, ()>(|| Ok(path.as_ref().to_path_buf()), opts)
Self::map_with_path_builder::<_, ()>(|| dummy_path_builder(path), opts)
.map_err(|e| e.unwrap_right())
}

Expand Down Expand Up @@ -910,7 +902,7 @@ where
cks: S,
) -> Result<Self, Error> {
Self::map_mut_with_path_builder_and_checksumer::<_, ()>(
|| Ok(path.as_ref().to_path_buf()),
|| dummy_path_builder(path),
opts,
open_options,
cks,
Expand Down Expand Up @@ -1021,12 +1013,8 @@ where
opts: Options,
cks: S,
) -> Result<GenericWalReader<K, V>, Error> {
Self::map_with_path_builder_and_checksumer::<_, ()>(
|| Ok(path.as_ref().to_path_buf()),
opts,
cks,
)
.map_err(|e| e.unwrap_right())
Self::map_with_path_builder_and_checksumer::<_, ()>(|| dummy_path_builder(path), opts, cks)
.map_err(|e| e.unwrap_right())
}

/// Open a write-ahead log backed by a file backed memory map in read only mode with the given [`Checksumer`].
Expand Down Expand Up @@ -1220,9 +1208,7 @@ where
Some(e) => e,
None => match self.insert_in(Among::Middle(key), Among::Right(value)) {
Ok(_) => Either::Right(Ok(())),
Err(Among::Left(e)) => Either::Right(Err(Either::Left(e))),
Err(Among::Right(e)) => Either::Right(Err(Either::Right(e))),
_ => unreachable!(),
Err(e) => Either::Right(Err(e.into_left_right())),
},
}
}
Expand All @@ -1247,9 +1233,7 @@ where
Some(e) => e,
None => match self.insert_in(Among::Right(key), Among::Middle(value)) {
Ok(_) => Either::Right(Ok(())),
Err(Among::Middle(e)) => Either::Right(Err(Either::Left(e))),
Err(Among::Right(e)) => Either::Right(Err(Either::Right(e))),
_ => unreachable!(),
Err(e) => Either::Right(Err(e.into_middle_right())),
},
}
}
Expand All @@ -1274,9 +1258,7 @@ where
Some(e) => e,
None => match self.insert_in(Among::Right(key), Among::Left(value())) {
Ok(_) => Either::Right(Ok(())),
Err(Among::Middle(e)) => Either::Right(Err(Either::Left(e))),
Err(Among::Right(e)) => Either::Right(Err(Either::Right(e))),
_ => unreachable!(),
Err(e) => Either::Right(Err(e.into_middle_right())),
},
}
}
Expand Down Expand Up @@ -1311,11 +1293,7 @@ where
) -> Result<(), Either<K::Error, Error>> {
self
.insert_in(Among::Middle(key), Among::Right(value))
.map_err(|e| match e {
Among::Left(e) => Either::Left(e),
Among::Right(e) => Either::Right(e),
_ => unreachable!(),
})
.map_err(Among::into_left_right)
}

/// Inserts a key in bytes format and value in structured format into the write-ahead log directly.
Expand Down Expand Up @@ -1479,11 +1457,7 @@ where
) -> Result<(), Either<V::Error, Error>> {
self
.insert_in(Among::Right(key), Among::Middle(value))
.map_err(|e| match e {
Among::Middle(e) => Either::Left(e),
Among::Right(e) => Either::Right(e),
_ => unreachable!(),
})
.map_err(Among::into_middle_right)
}

fn insert_in(
Expand Down Expand Up @@ -1577,3 +1551,8 @@ where
)
}
}

#[inline]
fn dummy_path_builder(p: impl AsRef<Path>) -> Result<PathBuf, ()> {
Ok(p.as_ref().to_path_buf())
}
2 changes: 2 additions & 0 deletions src/swmr/generic/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ fn construct_map_file() {
.insert(&person, &"My name is Alice!".to_string())
.unwrap();
assert_eq!(wal.get(&person).unwrap().value(), "My name is Alice!");

assert_eq!(*wal.path().unwrap().as_ref(), path);
}

let pr = PersonRef {
Expand Down
16 changes: 15 additions & 1 deletion src/swmr/generic/traits/impls/bytes.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::borrow::Borrow;
use dbutils::equivalent::*;
use std::{borrow::Cow, sync::Arc};

Expand Down Expand Up @@ -77,6 +78,12 @@ impl<'a> TypeRef<'a> for &'a [u8] {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SliceRef<'a>(&'a [u8]);

impl<'a> Borrow<[u8]> for SliceRef<'a> {
fn borrow(&self) -> &[u8] {
self.0
}
}

impl<'a> From<&'a [u8]> for SliceRef<'a> {
fn from(src: &'a [u8]) -> Self {
Self(src)
Expand All @@ -101,6 +108,13 @@ impl AsRef<[u8]> for SliceRef<'_> {
}
}

impl core::ops::Deref for SliceRef<'_> {
type Target = [u8];
fn deref(&self) -> &Self::Target {
self.0
}
}

impl PartialEq<[u8]> for SliceRef<'_> {
fn eq(&self, other: &[u8]) -> bool {
self.0 == other
Expand Down Expand Up @@ -151,7 +165,7 @@ impl PartialEq<SliceRef<'_>> for &Vec<u8> {

impls! {
Cow<'_, [u8]>,
// &'static [u8] // TODO: implement this
&'static [u8],
Vec<u8>,
Box<[u8]>,
Arc<[u8]>,
Expand Down
12 changes: 6 additions & 6 deletions src/swmr/generic/traits/impls/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ impl Borrow<str> for Str<'_> {
}
}

impl<'a> Borrow<&'a str> for Str<'a> {
fn borrow(&self) -> &&'a str {
&self.0
}
}
// impl<'a> Borrow<&'a str> for Str<'a> {
// fn borrow(&self) -> &&'a str {
// &self.0
// }
// }

impl core::ops::Deref for Str<'_> {
type Target = str;
Expand Down Expand Up @@ -197,7 +197,7 @@ impl PartialOrd<Str<'_>> for &str {

impls! {
Cow<'_, str>,
// &'static str, TODO: add back this
&'static str,
String,
Arc<str>,
Box<str>,
Expand Down

0 comments on commit e5e09d2

Please sign in to comment.