[−][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();
}
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.
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
}
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
}
pub async fn read<'_>(&'_ self, key: impl Key) -> Result<Vec<u8>>
[src]
Reads the first found data matching given key,
if are no records with matching key, returns Error::RecordNotFound
Examples
async fn read_data() {
let key = 42u64.to_be_bytes().to_vec();
let data = storage.read(key).await;
}
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,
if are no records with matching key, returns Error::RecordNotFound
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;
}
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
#[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);
Trait Implementations
impl<K> Drop for Storage<K>
[src]
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]
Auto Trait Implementations
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>
impl<K> !RefUnwindSafe for Storage<K>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
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, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
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<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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,