use std::ops::{Bound, ControlFlow};
use armour_core::Typ;
use crate::armour::inspection::ScanCapability;
use crate::codec::InspectionEncoding;
use crate::error::DbResult;
use crate::key::Key;
use armour_core::StorageClass;
pub(crate) type Step = ControlFlow<()>;
pub(crate) type RowFn<'f, K, V> = &'f mut dyn FnMut(&K, &V) -> DbResult<Step>;
#[cfg_attr(not(feature = "rpc"), allow(dead_code))]
pub(crate) type KeyFn<'f, K> = &'f mut dyn FnMut(&K) -> DbResult<Step>;
pub(crate) type FallibleRowFn<'f, K, V> = &'f mut dyn FnMut(DbResult<(&K, &V)>) -> Step;
#[cfg_attr(not(feature = "rpc"), allow(dead_code))]
pub(crate) trait Wire<V>: Send + Sync + 'static {
const PASSTHROUGH: bool = false;
fn encode_to(&self, value: &V, out: &mut Vec<u8>) -> DbResult<()>;
fn decode(&self, bytes: &[u8]) -> DbResult<V>;
fn size(&self, value: &V) -> DbResult<u32>;
fn encode(&self, value: &V) -> DbResult<Vec<u8>> {
let mut out = Vec::new();
self.encode_to(value, &mut out)?;
Ok(out)
}
fn decode_batch_item(&self, bytes: &[u8]) -> DbResult<V> {
self.decode(bytes)
.map_err(|_| crate::error::DbError::Client("invalid value bytes in batch"))
}
fn validate_stored(&self, _raw: &[u8]) -> DbResult<()> {
Err(crate::error::DbError::Client(
"wire does not validate stored bytes",
))
}
}
use crate::held_ops::HeldOps;
#[cfg_attr(not(feature = "rpc"), allow(dead_code))]
pub(crate) trait Access: Send + Sync + 'static {
type Key: Key;
type Val;
type Shard<'a>: HeldOps<Key = Self::Key, Val = Self::Val>
where
Self: 'a;
const STORAGE: StorageClass;
const RAW_WIRE_BYTES: bool = false;
fn encoding(&self, ty: &Typ) -> InspectionEncoding;
fn approx_len(&self) -> u64;
fn rpc_exact_count(&self) -> DbResult<u64>;
fn inspection_exact_count(&self) -> DbResult<u64>;
fn scan_capability(&self) -> ScanCapability;
fn inspection_shard_count(&self) -> usize {
1
}
fn reversed(&self) -> bool;
fn with_value<R>(
&self,
key: &Self::Key,
f: impl FnOnce(&Self::Val) -> R,
) -> DbResult<Option<R>>;
fn contains(&self, key: &Self::Key) -> DbResult<bool>;
fn stored_bytes(&self, _key: &Self::Key) -> DbResult<Option<Vec<u8>>> {
Ok(None)
}
fn entry_len<W: Wire<Self::Val>>(&self, key: &Self::Key, wire: &W) -> DbResult<Option<u32>> {
self.with_value(key, |v| wire.size(v))?.transpose()
}
fn with_first<R>(&self, f: impl FnOnce(&Self::Key, &Self::Val) -> R) -> DbResult<Option<R>>;
fn with_last<R>(&self, f: impl FnOnce(&Self::Key, &Self::Val) -> R) -> DbResult<Option<R>>;
fn scan_range(
&self,
start: Bound<&Self::Key>,
end: Bound<&Self::Key>,
f: RowFn<'_, Self::Key, Self::Val>,
) -> DbResult<()>;
fn try_scan_range(
&self,
start: Bound<&Self::Key>,
end: Bound<&Self::Key>,
batch: usize,
f: RowFn<'_, Self::Key, Self::Val>,
) -> DbResult<()>;
fn scan_keys(
&self,
start: Bound<&Self::Key>,
end: Bound<&Self::Key>,
f: KeyFn<'_, Self::Key>,
) -> DbResult<()>;
fn scan_all(&self, f: FallibleRowFn<'_, Self::Key, Self::Val>);
fn undecodable_rows(&self) -> u64 {
0
}
fn effective_projection_limits(&self) -> Option<(usize, usize)> {
None
}
fn put(&self, key: &Self::Key, value: Self::Val) -> DbResult<()>;
fn put_ref(&self, key: &Self::Key, value: &Self::Val) -> DbResult<()>;
fn delete(&self, key: &Self::Key) -> DbResult<()>;
fn atomic_at<R>(
&self,
key: &Self::Key,
f: impl FnOnce(&mut Self::Shard<'_>) -> DbResult<R>,
) -> DbResult<R>;
}