forked from rust-rocksdb/rust-rocksdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add widecolumns get put and columns api
- Loading branch information
1 parent
7b031f4
commit 9da584a
Showing
7 changed files
with
210 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
use crate::ffi; | ||
use std::{ | ||
marker::PhantomData, | ||
ptr::{null, slice_from_raw_parts}, | ||
}; | ||
|
||
pub struct WideColumn<'a> { | ||
pub name: &'a [u8], | ||
pub value: &'a [u8], | ||
} | ||
|
||
pub struct WideColumns<'a> { | ||
inner: *const ffi::rocksdb_widecolumns_t, | ||
columns_size: usize, | ||
iter: PhantomData<&'a ()>, | ||
} | ||
|
||
impl<'a> WideColumns<'a> { | ||
pub(crate) unsafe fn from_c(inner: *const ffi::rocksdb_widecolumns_t) -> Self { | ||
Self { | ||
inner, | ||
columns_size: ffi::rocksdb_widecolumns_len(inner), | ||
iter: PhantomData, | ||
} | ||
} | ||
|
||
pub fn len(&self) -> usize { | ||
Check failure on line 27 in src/wide_columns.rs GitHub Actions / clippystruct `WideColumns` has a public `len` method, but no `is_empty` method
Check failure on line 27 in src/wide_columns.rs GitHub Actions / clippystruct `WideColumns` has a public `len` method, but no `is_empty` method
|
||
self.columns_size | ||
} | ||
|
||
pub unsafe fn get_column_name_unchecked(&self, idx: usize) -> &[u8] { | ||
let mut name_len: usize = 0; | ||
let name_len_ptr: *mut usize = &mut name_len; | ||
let name = null::<*const i8>() as *mut *const i8; | ||
ffi::rocksdb_widecolumns_name(self.inner, idx, name, name_len_ptr); | ||
&*slice_from_raw_parts(name as *const u8, name_len) | ||
} | ||
|
||
pub unsafe fn get_column_value_unchecked(&self, idx: usize) -> &[u8] { | ||
let mut value_len: usize = 0; | ||
let value_len_ptr: *mut usize = &mut value_len; | ||
let value = null::<*const i8>() as *mut *const i8; | ||
ffi::rocksdb_widecolumns_value(self.inner, idx, value, value_len_ptr); | ||
&*slice_from_raw_parts(value as *const u8, value_len) | ||
} | ||
|
||
pub unsafe fn get_column_unchecked(&self, idx: usize) -> WideColumn { | ||
WideColumn { | ||
name: self.get_column_name_unchecked(idx), | ||
value: self.get_column_value_unchecked(idx), | ||
} | ||
} | ||
} | ||
|
||
pub struct PinnableWideColumns<'a> { | ||
inner: *const ffi::rocksdb_pinnablewidecolumns_t, | ||
columns_size: usize, | ||
iter: PhantomData<&'a ()>, | ||
} | ||
|
||
impl<'a> PinnableWideColumns<'a> { | ||
pub(crate) unsafe fn from_c(inner: *const ffi::rocksdb_pinnablewidecolumns_t) -> Self { | ||
Self { | ||
inner, | ||
columns_size: ffi::rocksdb_pinnablewidecolumns_len(inner), | ||
iter: PhantomData, | ||
} | ||
} | ||
|
||
pub fn len(&self) -> usize { | ||
Check failure on line 70 in src/wide_columns.rs GitHub Actions / clippystruct `PinnableWideColumns` has a public `len` method, but no `is_empty` method
Check failure on line 70 in src/wide_columns.rs GitHub Actions / clippystruct `PinnableWideColumns` has a public `len` method, but no `is_empty` method
|
||
self.columns_size | ||
} | ||
|
||
pub unsafe fn get_column_name_unchecked(&self, idx: usize) -> &[u8] { | ||
let mut name_len: usize = 0; | ||
let name_len_ptr: *mut usize = &mut name_len; | ||
let name = null::<*const i8>() as *mut *const i8; | ||
ffi::rocksdb_pinnablewidecolumns_name(self.inner, idx, name, name_len_ptr); | ||
&*slice_from_raw_parts(name as *const u8, name_len) | ||
} | ||
|
||
pub unsafe fn get_column_value_unchecked(&self, idx: usize) -> &[u8] { | ||
let mut value_len: usize = 0; | ||
let value_len_ptr: *mut usize = &mut value_len; | ||
let value = null::<*const i8>() as *mut *const i8; | ||
ffi::rocksdb_pinnablewidecolumns_value(self.inner, idx, value, value_len_ptr); | ||
&*slice_from_raw_parts(value as *const u8, value_len) | ||
} | ||
|
||
pub unsafe fn get_column_unchecked(&self, idx: usize) -> WideColumn { | ||
WideColumn { | ||
name: self.get_column_name_unchecked(idx), | ||
value: self.get_column_value_unchecked(idx), | ||
} | ||
} | ||
} |