1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
// #![warn(clippy::all)]
// #![warn(clippy::nursery)]
// #![warn(clippy::pedantic)]
// #![warn(clippy::cargo)]

//! # pearl
//!
//! The `pearl` library is a Append only key-value blob storage on disk.
//! Crate `pearl` provides [`Futures 0.3`] interface. Tokio runtime required.
//!
//! [`Futures 0.3`]: https://rust-lang-nursery.github.io/futures-api-docs#latest
//!
//! # Examples
//! The following example shows a storage building and initialization.
//! For more advanced usage see the benchmark tool as the example
//!
//! ```no-run
//! use pearl::{Storage, Builder, Key};
//!
//! struct Id(String);
//!
//! impl AsRef<[u8]> for Id {
//!     fn as_ref(&self) -> &[u8] {
//!         self.0.as_bytes()
//!     }
//! }
//!
//! impl Key for Id {
//!     const LEN: u16 = 4;
//! }
//!
//! #[tokio::main]
//! async fn main() {
//!     let mut storage: Storage<Id> = 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();
//!     let key = Id("test".to_string());
//!     let data = b"Hello World!".to_vec();
//!     storage.write(key, data).await.unwrap();
//! }
//! ```

#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate futures;

mod blob;
mod error;
mod record;
mod storage;

pub use blob::{filter, Entries, Entry};
pub use error::{Error, Kind as ErrorKind, Result};
pub use record::Meta;
pub use storage::{Builder, Key, ReadAll, Storage};

mod prelude {
    pub(crate) type PinBox<T> = Pin<Box<T>>;
    pub(crate) use super::*;
    pub(crate) use bincode::{deserialize, serialize, serialize_into, serialized_size};
    pub(crate) use blob::{self, Blob, BloomConfig, File, Location};
    pub(crate) use crc::crc32::checksum_castagnoli as crc32;
    pub(crate) use futures::{
        future::{self, Future, FutureExt, TryFutureExt},
        io::{AsyncRead, AsyncReadExt, AsyncSeek, AsyncSeekExt, AsyncWrite, AsyncWriteExt},
        lock::{Mutex, MutexGuard},
        stream::{futures_unordered::FuturesUnordered, Stream, StreamExt, TryStreamExt},
    };
    pub(crate) use record::{Header as RecordHeader, Record};
    pub(crate) use std::{
        cell::RefCell,
        cmp::Ordering as CmpOrdering,
        collections::HashMap,
        convert::TryInto,
        error,
        fmt::{Debug, Display, Formatter, Result as FmtResult},
        fs::{self, DirEntry, File as StdFile, OpenOptions},
        io::{
            Error as IOError, ErrorKind as IOErrorKind, Read, Result as IOResult, Seek, SeekFrom,
            Write,
        },
        marker::PhantomData,
        num::TryFromIntError,
        os::unix::fs::{FileExt, OpenOptionsExt},
        path::{Path, PathBuf},
        pin::Pin,
        sync::{
            atomic::{AtomicBool, AtomicUsize, Ordering},
            Arc,
        },
        task::{Context, Poll, Waker},
        time::Duration,
    };
    pub(crate) use tokio::time::{delay_for, interval};
    pub(crate) use {Key, Meta};
}