[][src]Struct pearl::Storage

pub struct Storage<K> { /* fields omitted */ }

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();
}

Methods

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]

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]

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 fn read_all<'a>(&'a self, key: &'a impl Key) -> ReadAll<'a, K>[src]

Returns stream producing entries with matching key

pub async fn close<'_>(&'_ self) -> Result<()>[src]

Stop blob updater and release lock file

Errors

Fails because of any IO errors

#[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) -> bool[src]

contains is used to check whether a key is in storage. Uses bloom filter under the hood, so false positive results are possible, but false negatives are not. In other words, contains returns either "possibly in storage" or "definitely not".

Trait Implementations

impl<K> Clone for Storage<K>[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

impl<K> Sync for Storage<K> where
    K: Sync

impl<K> Unpin for Storage<K> where
    K: Unpin

impl<K> !UnwindSafe for Storage<K>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,