[−][src]Struct pearl::Storage
A main storage struct.
This type is clonable, cloning it will only create a new reference,
not a new storage.
Storage has a type parameter K.
To perform read/write operations K must implement Key
trait.
Examples
use pearl::{Storage, Builder, Key};
#[tokio::main]
async fn main() {
let mut storage: Storage<String> = Builder::new()
.work_dir("/tmp/pearl/")
.max_blob_size(1_000_000)
.max_data_in_blob(1_000_000_000)
.blob_file_name_prefix("pearl-test")
.build()
.unwrap();
storage.init().await.unwrap();
}
Implementations
impl<K> Storage<K>
[src]
pub async fn init<'_>(&'_ mut self) -> Result<()>
[src]
init()
used to prepare all environment to further work.
Storage works in directory provided to builder. If directory don't exist, storage creates it, otherwise tries to init existing storage.
Errors
Returns error in case of failures with IO operations or if some of the required params are missed.
pub async fn write<'_>(&'_ self, key: impl Key, value: Vec<u8>) -> Result<()>
[src]
Writes data
to active blob asyncronously. If active blob reaches it limit, creates new
and closes old.
Examples
async fn write_data() {
let key = 42u64.to_be_bytes().to_vec();
let data = b"async written to blob".to_vec();
storage.write(key, data).await
}
Errors
Fails with the same errors as write_with
pub async fn write_with<'_>(
&'_ self,
key: impl Key,
value: Vec<u8>,
meta: Meta
) -> Result<()>
[src]
&'_ self,
key: impl Key,
value: Vec<u8>,
meta: Meta
) -> Result<()>
Similar to write
but with metadata
Examples
async fn write_data() {
let key = 42u64.to_be_bytes().to_vec();
let data = b"async written to blob".to_vec();
let meta = Meta::new();
meta.insert("version".to_string(), b"1.0".to_vec());
storage.write_with(&key, data, meta).await
}
Errors
Fails if duplicates are not allowed and record already exists.
pub async fn read<'_>(&'_ self, key: impl Key) -> Result<Vec<u8>>
[src]
Reads the first found data matching given key.
Examples
async fn read_data() {
let key = 42u64.to_be_bytes().to_vec();
let data = storage.read(key).await;
}
Errors
Same as read_with
pub async fn read_with<'_, '_>(
&'_ self,
key: impl Key,
meta: &'_ Meta
) -> Result<Vec<u8>>
[src]
&'_ self,
key: impl Key,
meta: &'_ Meta
) -> Result<Vec<u8>>
Reads data matching given key and metadata
Examples
async fn read_data() {
let key = 42u64.to_be_bytes().to_vec();
let meta = Meta::new();
meta.insert("version".to_string(), b"1.0".to_vec());
let data = storage.read(&key, &meta).await;
}
Errors
Return error if record is not found.
pub async fn read_all<'_, '_>(&'_ self, key: &'_ impl Key) -> Result<Vec<Entry>>
[src]
pub async fn close<'_>(&'_ self) -> Result<()>
[src]
#[must_use]pub fn blobs_count(&self) -> usize
[src]
blob_count
returns number of closed blobs plus one active, if there is some.
Examples
use pearl::Builder;
let mut storage = Builder::new().work_dir("/tmp/pearl/").build::<f64>();
storage.init().await;
assert_eq!(storage.blobs_count(), 1);
pub async fn contains<'_>(&'_ self, key: impl Key) -> Result<bool>
[src]
contains
is used to check whether a key is in storage.
Slower than check_bloom
, because doesn't prevent disk IO operations.
contains
returns either "definitely in storage" or "definitely not".
Errors
Fails because of any IO errors
pub async fn check_bloom<'_>(&'_ self, key: impl Key) -> Option<bool>
[src]
check_bloom
is used to check whether a key is in storage.
If bloom filter opt out, returns None
.
Uses bloom filter under the hood, so false positive results are possible,
but false negatives are not.
In other words, check_bloom
returns either "possibly in storage" or "definitely not".
pub async fn records_count<'_>(&'_ self) -> usize
[src]
Total records count in storage.
pub async fn records_count_detailed<'_>(&'_ self) -> Vec<(usize, usize)>
[src]
Records count per blob. Format: (blob_id
, count). Last value is from active blob.
pub async fn records_count_in_active_blob<'_>(&'_ self) -> Option<usize>
[src]
Records count in active blob. Returns None if active blob not set or any IO error occured.
pub async fn fsyncdata<'_>(&'_ self) -> IOResult<()>
[src]
Syncronizes data and metadata of the active blob with the filesystem.
Like tokio::std::fs::File::sync_data
, this function will attempt to ensure that in-core data reaches the filesystem before returning.
May not syncronize file metadata to the file system.
Errors
Fails because of any IO errors
Trait Implementations
impl<K> Clone for Storage<K>
[src]
#[must_use]fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<K: Debug> Debug for Storage<K>
[src]
impl<K> Drop for Storage<K>
[src]
Auto Trait Implementations
impl<K> !RefUnwindSafe for Storage<K>
impl<K> Send for Storage<K> where
K: Send,
K: Send,
impl<K> Sync for Storage<K> where
K: Sync,
K: Sync,
impl<K> Unpin for Storage<K> where
K: Unpin,
K: Unpin,
impl<K> !UnwindSafe for Storage<K>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Conv for T
impl<T> FmtForward for T
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Self: Binary,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Self: Display,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Self: LowerExp,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Self: LowerHex,
fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
Self: Octal,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Self: Pointer,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Self: UpperExp,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Self: UpperHex,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pipe for T
impl<T> PipeAsRef for T
fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
R: 'a,
Self: AsRef<T>,
T: 'a,
R: 'a,
Self: AsRef<T>,
T: 'a,
fn pipe_as_mut<'a, T, R>(&'a mut self, func: impl FnOnce(&'a mut T) -> R) -> R where
R: 'a,
Self: AsMut<T>,
T: 'a,
R: 'a,
Self: AsMut<T>,
T: 'a,
impl<T> PipeBorrow for T
fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
R: 'a,
Self: Borrow<T>,
T: 'a,
R: 'a,
Self: Borrow<T>,
T: 'a,
fn pipe_borrow_mut<'a, T, R>(
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
R: 'a,
Self: BorrowMut<T>,
T: 'a,
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
R: 'a,
Self: BorrowMut<T>,
T: 'a,
impl<T> PipeDeref for T
fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where
R: 'a,
Self: Deref,
R: 'a,
Self: Deref,
fn pipe_deref_mut<'a, R>(
&'a mut self,
func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
R: 'a,
Self: DerefMut,
&'a mut self,
func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
R: 'a,
Self: DerefMut,
impl<T> PipeRef for T
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
R: 'a,
fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
R: 'a,
impl<T> Tap for T
fn tap<F, R>(self, func: F) -> Self where
F: FnOnce(&Self) -> R,
F: FnOnce(&Self) -> R,
fn tap_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&Self) -> R,
F: FnOnce(&Self) -> R,
fn tap_mut<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
F: FnOnce(&mut Self) -> R,
fn tap_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
F: FnOnce(&mut Self) -> R,
impl<T, U> TapAsRef<U> for T where
U: ?Sized,
U: ?Sized,
fn tap_ref<F, R>(self, func: F) -> Self where
F: FnOnce(&T) -> R,
Self: AsRef<T>,
F: FnOnce(&T) -> R,
Self: AsRef<T>,
fn tap_ref_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&T) -> R,
Self: AsRef<T>,
F: FnOnce(&T) -> R,
Self: AsRef<T>,
fn tap_ref_mut<F, R>(self, func: F) -> Self where
F: FnOnce(&mut T) -> R,
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
Self: AsMut<T>,
fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut T) -> R,
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
Self: AsMut<T>,
impl<T, U> TapBorrow<U> for T where
U: ?Sized,
U: ?Sized,
fn tap_borrow<F, R>(self, func: F) -> Self where
F: FnOnce(&T) -> R,
Self: Borrow<T>,
F: FnOnce(&T) -> R,
Self: Borrow<T>,
fn tap_borrow_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&T) -> R,
Self: Borrow<T>,
F: FnOnce(&T) -> R,
Self: Borrow<T>,
fn tap_borrow_mut<F, R>(self, func: F) -> Self where
F: FnOnce(&mut T) -> R,
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Self: BorrowMut<T>,
fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut T) -> R,
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Self: BorrowMut<T>,
impl<T> TapDeref for T
fn tap_deref<F, R>(self, func: F) -> Self where
F: FnOnce(&Self::Target) -> R,
Self: Deref,
F: FnOnce(&Self::Target) -> R,
Self: Deref,
fn tap_deref_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&Self::Target) -> R,
Self: Deref,
F: FnOnce(&Self::Target) -> R,
Self: Deref,
fn tap_deref_mut<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self::Target) -> R,
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Self: DerefMut,
fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self::Target) -> R,
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Self: DerefMut,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> TryConv for T
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,