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

Rename RedbValue and RedbKey #753

Merged
merged 2 commits into from
Feb 3, 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
12 changes: 6 additions & 6 deletions examples/special_values.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use redb::{
Database, Error, ReadableTable, RedbKey, RedbValue, Table, TableDefinition, TableHandle,
Database, Error, Key, ReadableTable, Table, TableDefinition, TableHandle, Value,
WriteTransaction,
};
use std::fs::{File, OpenOptions};
Expand Down Expand Up @@ -40,7 +40,7 @@ struct SpecialValuesTransaction<'db> {
}

impl<'db> SpecialValuesTransaction<'db> {
fn open_table<K: RedbKey + 'static, V: RedbValue + 'static>(
fn open_table<K: Key + 'static, V: Value + 'static>(
&mut self,
table: TableDefinition<K, V>,
) -> SpecialValuesTable<K, V> {
Expand All @@ -58,13 +58,13 @@ impl<'db> SpecialValuesTransaction<'db> {
}
}

struct SpecialValuesTable<'txn, K: RedbKey + 'static, V: RedbValue + 'static> {
struct SpecialValuesTable<'txn, K: Key + 'static, V: Value + 'static> {
inner: Table<'txn, K, (u64, u64)>,
file: &'txn mut File,
_value_type: PhantomData<V>,
}

impl<'txn, K: RedbKey + 'static, V: RedbValue + 'static> SpecialValuesTable<'txn, K, V> {
impl<'txn, K: Key + 'static, V: Value + 'static> SpecialValuesTable<'txn, K, V> {
fn insert(&mut self, key: K::SelfType<'_>, value: V::SelfType<'_>) {
// Append to end of file
let offset = self.file.seek(SeekFrom::End(0)).unwrap();
Expand All @@ -87,12 +87,12 @@ impl<'txn, K: RedbKey + 'static, V: RedbValue + 'static> SpecialValuesTable<'txn
}
}

struct ValueAccessor<V: RedbValue + 'static> {
struct ValueAccessor<V: Value + 'static> {
data: Vec<u8>,
_value_type: PhantomData<V>,
}

impl<V: RedbValue + 'static> ValueAccessor<V> {
impl<V: Value + 'static> ValueAccessor<V> {
fn value(&self) -> V::SelfType<'_> {
V::from_bytes(&self.data)
}
Expand Down
4 changes: 2 additions & 2 deletions src/complex_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::types::{RedbValue, TypeName};
use crate::types::{TypeName, Value};

// Encode len as a varint and store it at the end of output
fn encode_varint_len(len: usize, output: &mut Vec<u8>) {
Expand Down Expand Up @@ -32,7 +32,7 @@ fn decode_varint_len(data: &[u8]) -> (usize, usize) {
}
}

impl<T: RedbValue> RedbValue for Vec<T> {
impl<T: Value> Value for Vec<T> {
type SelfType<'a> = Vec<T::SelfType<'a>>
where
Self: 'a;
Expand Down
30 changes: 15 additions & 15 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::tree_store::{
InternalTableDefinition, PageHint, PageNumber, RawBtree, SerializedSavepoint, TableTreeMut,
TableType, TransactionalMemory, PAGE_SIZE,
};
use crate::types::{RedbKey, RedbValue};
use crate::types::{Key, Value};
use crate::{
CompactionError, DatabaseError, Durability, ReadOnlyTable, SavepointError, StorageError,
};
Expand Down Expand Up @@ -108,13 +108,13 @@ impl Sealed for UntypedMultimapTableHandle {}
///
/// Note that the lifetime of the `K` and `V` type parameters does not impact the lifetimes of the data
/// that is stored or retreived from the table
pub struct TableDefinition<'a, K: RedbKey + 'static, V: RedbValue + 'static> {
pub struct TableDefinition<'a, K: Key + 'static, V: Value + 'static> {
name: &'a str,
_key_type: PhantomData<K>,
_value_type: PhantomData<V>,
}

impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> TableDefinition<'a, K, V> {
impl<'a, K: Key + 'static, V: Value + 'static> TableDefinition<'a, K, V> {
/// Construct a new table with given `name`
///
/// ## Invariant
Expand All @@ -130,23 +130,23 @@ impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> TableDefinition<'a, K, V>
}
}

impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> TableHandle for TableDefinition<'a, K, V> {
impl<'a, K: Key + 'static, V: Value + 'static> TableHandle for TableDefinition<'a, K, V> {
fn name(&self) -> &str {
self.name
}
}

impl<K: RedbKey, V: RedbValue> Sealed for TableDefinition<'_, K, V> {}
impl<K: Key, V: Value> Sealed for TableDefinition<'_, K, V> {}

impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Clone for TableDefinition<'a, K, V> {
impl<'a, K: Key + 'static, V: Value + 'static> Clone for TableDefinition<'a, K, V> {
fn clone(&self) -> Self {
*self
}
}

impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Copy for TableDefinition<'a, K, V> {}
impl<'a, K: Key + 'static, V: Value + 'static> Copy for TableDefinition<'a, K, V> {}

impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Display for TableDefinition<'a, K, V> {
impl<'a, K: Key + 'static, V: Value + 'static> Display for TableDefinition<'a, K, V> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
Expand All @@ -166,13 +166,13 @@ impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Display for TableDefiniti
///
/// Note that the lifetime of the `K` and `V` type parameters does not impact the lifetimes of the data
/// that is stored or retreived from the table
pub struct MultimapTableDefinition<'a, K: RedbKey + 'static, V: RedbKey + 'static> {
pub struct MultimapTableDefinition<'a, K: Key + 'static, V: Key + 'static> {
name: &'a str,
_key_type: PhantomData<K>,
_value_type: PhantomData<V>,
}

impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTableDefinition<'a, K, V> {
impl<'a, K: Key + 'static, V: Key + 'static> MultimapTableDefinition<'a, K, V> {
pub const fn new(name: &'a str) -> Self {
assert!(!name.is_empty());
Self {
Expand All @@ -183,25 +183,25 @@ impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTableDefinition<'a,
}
}

impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTableHandle
impl<'a, K: Key + 'static, V: Key + 'static> MultimapTableHandle
for MultimapTableDefinition<'a, K, V>
{
fn name(&self) -> &str {
self.name
}
}

impl<K: RedbKey, V: RedbKey> Sealed for MultimapTableDefinition<'_, K, V> {}
impl<K: Key, V: Key> Sealed for MultimapTableDefinition<'_, K, V> {}

impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> Clone for MultimapTableDefinition<'a, K, V> {
impl<'a, K: Key + 'static, V: Key + 'static> Clone for MultimapTableDefinition<'a, K, V> {
fn clone(&self) -> Self {
*self
}
}

impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> Copy for MultimapTableDefinition<'a, K, V> {}
impl<'a, K: Key + 'static, V: Key + 'static> Copy for MultimapTableDefinition<'a, K, V> {}

impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> Display for MultimapTableDefinition<'a, K, V> {
impl<'a, K: Key + 'static, V: Key + 'static> Display for MultimapTableDefinition<'a, K, V> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub use table::{
};
pub use transactions::{DatabaseStats, Durability, ReadTransaction, WriteTransaction};
pub use tree_store::{AccessGuard, AccessGuardMut, Savepoint};
pub use types::{MutInPlaceValue, RedbKey, RedbValue, TypeName};
pub use types::{Key, MutInPlaceValue, TypeName, Value};

type Result<T = (), E = StorageError> = std::result::Result<T, E>;

Expand Down
Loading
Loading