#![cfg_attr(docsrs, feature(doc_cfg))]
mod maybe;
pub mod storage_adapter;
mod storage_handle;
mod storage_sync;
mod storage_value_io;
pub mod store;
mod store_key;
mod store_prefix;
pub mod byte_range;
use byte_range::{ByteOffset, InvalidByteRangeError};
pub use maybe::{MaybeSend, MaybeSync};
#[cfg(feature = "async")]
mod storage_async;
#[cfg(feature = "tests")]
pub mod store_test;
use std::sync::Arc;
pub use storage_value_io::StorageValueIO;
pub use store_key::{StoreKey, StoreKeyError, StoreKeys};
pub use store_prefix::{StorePrefix, StorePrefixError, StorePrefixes};
use thiserror::Error;
#[cfg(feature = "async")]
pub use self::storage_async::{
async_discover_children, async_store_set_partial_many, AsyncListableStorageTraits,
AsyncReadableListableStorageTraits, AsyncReadableStorageTraits,
AsyncReadableWritableListableStorageTraits, AsyncReadableWritableStorageTraits,
AsyncWritableStorageTraits,
};
pub use self::storage_handle::StorageHandle;
pub use self::storage_sync::{
discover_children, store_set_partial_many, AtomicRenameStorageTraits, ListableStorageTraits,
ReadableListableStorageTraits, ReadableStorageTraits, ReadableWritableListableStorageTraits,
ReadableWritableStorageTraits, WritableStorageTraits,
};
pub type ReadableStorage = Arc<dyn ReadableStorageTraits>;
pub type WritableStorage = Arc<dyn WritableStorageTraits>;
pub type ReadableWritableStorage = Arc<dyn ReadableWritableStorageTraits>;
pub type ListableStorage = Arc<dyn ListableStorageTraits>;
pub type ReadableListableStorage = Arc<dyn ReadableListableStorageTraits>;
pub type ReadableWritableListableStorage = Arc<dyn ReadableWritableListableStorageTraits>;
#[cfg(feature = "async")]
pub type AsyncReadableStorage = Arc<dyn AsyncReadableStorageTraits>;
#[cfg(feature = "async")]
pub type AsyncWritableStorage = Arc<dyn AsyncWritableStorageTraits>;
#[cfg(feature = "async")]
pub type AsyncReadableWritableStorage = Arc<dyn AsyncReadableWritableStorageTraits>;
#[cfg(feature = "async")]
pub type AsyncListableStorage = Arc<dyn AsyncListableStorageTraits>;
#[cfg(feature = "async")]
pub type AsyncReadableListableStorage = Arc<dyn AsyncReadableListableStorageTraits>;
#[cfg(feature = "async")]
pub type AsyncReadableWritableListableStorage = Arc<dyn AsyncReadableWritableListableStorageTraits>;
pub type Bytes = bytes::Bytes;
pub type MaybeBytes = Option<Bytes>;
type BytesIterator<'a> = Box<dyn Iterator<Item = Result<Bytes, StorageError>> + 'a>;
pub type MaybeBytesIterator<'a> = Option<BytesIterator<'a>>;
#[cfg(feature = "async")]
type AsyncBytesIterator<'a> = futures::stream::BoxStream<'a, Result<Bytes, StorageError>>;
#[cfg(feature = "async")]
pub type AsyncMaybeBytesIterator<'a> = Option<AsyncBytesIterator<'a>>;
pub trait MaybeSendOffsetBytesIterator<T>: Iterator<Item = (ByteOffset, T)> + MaybeSend {}
impl<I, T> MaybeSendOffsetBytesIterator<T> for I where
I: Iterator<Item = (ByteOffset, T)> + MaybeSend
{
}
pub type OffsetBytesIterator<'a, T = Bytes> = Box<dyn MaybeSendOffsetBytesIterator<T> + 'a>;
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
#[allow(dead_code)]
pub struct StoreKeysPrefixes {
keys: StoreKeys,
prefixes: StorePrefixes,
}
impl StoreKeysPrefixes {
#[must_use]
pub fn new(keys: StoreKeys, prefixes: StorePrefixes) -> Self {
Self { keys, prefixes }
}
#[must_use]
pub const fn keys(&self) -> &StoreKeys {
&self.keys
}
#[must_use]
pub const fn prefixes(&self) -> &StorePrefixes {
&self.prefixes
}
}
#[derive(Debug, Clone, Error)]
pub enum StorageError {
#[error("a write operation was attempted on a read only store")]
ReadOnly,
#[error(transparent)]
IOError(#[from] Arc<std::io::Error>),
#[error("error parsing metadata for {0}: {1}")]
InvalidMetadata(StoreKey, String),
#[error("missing metadata for store prefix {0}")]
MissingMetadata(StorePrefix),
#[error("invalid store prefix {0}")]
StorePrefixError(#[from] StorePrefixError),
#[error("invalid store key {0}")]
InvalidStoreKey(#[from] StoreKeyError),
#[error("invalid byte range {0}")]
InvalidByteRangeError(#[from] InvalidByteRangeError),
#[error("{0}")]
Unsupported(String),
#[error("{0}")]
UnknownKeySize(StoreKey),
#[error("{0}")]
Other(String),
}
impl From<std::io::Error> for StorageError {
fn from(err: std::io::Error) -> Self {
Self::IOError(Arc::new(err))
}
}
impl From<&str> for StorageError {
fn from(err: &str) -> Self {
Self::Other(err.to_string())
}
}
impl From<String> for StorageError {
fn from(err: String) -> Self {
Self::Other(err)
}
}