Struct GappyMemoryStore
pub struct GappyMemoryStore { /* private fields */ }memory only.Expand description
A conformant store whose positions advance by a stride, never by one.
Rejects: a read-model handler that computes its next position by adding one. Positions are an opaque ordering key and the specification permits gaps, but every store an application author has met assigns them densely, so the input separating a correct handler from an incorrect one never occurs in-process. This is that input, and it is conformant: it runs the full conformance suite, because gaps are a freedom VT-11 grants rather than a defect.
A real adapter reaches the same shape by allocating from a sequence with
CACHE 7, by encoding a shard id in the low bits, or by using a transaction
id as the position.
§Panics
append panics if the position space is exhausted — if previous + stride
would overflow u64. Wrapping instead would break the strict monotonicity
this store exists to demonstrate it keeps, and there is no error to report
it through: Error is
MemoryStoreError, which is uninhabited because this store has no failure
modes of its own. Reaching it takes about 2^64 / stride appends.
§Examples
use core::num::NonZeroU64;
use happenstance_core::{AppendError, Event, EventStore};
use happenstance_core::MemoryStoreError;
use happenstance_testkit::{GappyMemoryStore, block_on};
let stride = NonZeroU64::new(7).ok_or("seven is not zero")?;
let store = GappyMemoryStore::with_stride(stride);
let seat = Event::new("Seated", &b"{}"[..])?;
let (first, second) = block_on(async {
let first = store.append(&[seat.clone()], None).await?;
let second = store.append(&[seat], None).await?;
Ok::<_, AppendError<MemoryStoreError>>((first, second))
})?;
// Strictly increasing, and never the next integer.
assert!(second > first);
assert_ne!(second.get(), first.get() + 1);Implementations§
§impl GappyMemoryStore
impl GappyMemoryStore
pub fn with_stride(stride: NonZeroU64) -> Self
pub fn with_stride(stride: NonZeroU64) -> Self
Creates an empty store whose positions advance by stride.
The first position assigned is stride itself, and each one after it is
previous + stride. There is deliberately no Default and no implicit
stride: a default here would be a number nobody chose, and the gap it
left would be an accident rather than an instrument.
A stride of one is legal and makes the store dense, which is a caller asking for a plain in-memory store; anything above one leaves a hole between every pair of consecutive events.
Trait Implementations§
§impl Debug for GappyMemoryStore
impl Debug for GappyMemoryStore
§impl SendEventStore for GappyMemoryStore
impl SendEventStore for GappyMemoryStore
§type Error = MemoryStoreError
type Error = MemoryStoreError
§fn read(
&self,
query: &Query,
options: ReadOptions,
) -> impl Stream<Item = Result<SequencedEvent, Self::Error>> + Send
fn read( &self, query: &Query, options: ReadOptions, ) -> impl Stream<Item = Result<SequencedEvent, Self::Error>> + Send
§async fn append(
&self,
events: &[Event],
condition: Option<&AppendCondition>,
) -> Result<SequencePosition, AppendError<Self::Error>>
async fn append( &self, events: &[Event], condition: Option<&AppendCondition>, ) -> Result<SequencePosition, AppendError<Self::Error>>
Auto Trait Implementations§
impl !Freeze for GappyMemoryStore
impl RefUnwindSafe for GappyMemoryStore
impl Send for GappyMemoryStore
impl Sync for GappyMemoryStore
impl Unpin for GappyMemoryStore
impl UnsafeUnpin for GappyMemoryStore
impl UnwindSafe for GappyMemoryStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<TraitVariantBlanketType> EventStore for TraitVariantBlanketTypewhere
TraitVariantBlanketType: SendEventStore,
impl<TraitVariantBlanketType> EventStore for TraitVariantBlanketTypewhere
TraitVariantBlanketType: SendEventStore,
Source§type Error = <TraitVariantBlanketType as SendEventStore>::Error
type Error = <TraitVariantBlanketType as SendEventStore>::Error
Source§fn read(
&self,
query: &Query,
options: ReadOptions,
) -> impl Stream<Item = Result<SequencedEvent, <TraitVariantBlanketType as EventStore>::Error>>
fn read( &self, query: &Query, options: ReadOptions, ) -> impl Stream<Item = Result<SequencedEvent, <TraitVariantBlanketType as EventStore>::Error>>
Source§async fn append(
&self,
events: &[Event],
condition: Option<&AppendCondition>,
) -> Result<SequencePosition, AppendError<<TraitVariantBlanketType as EventStore>::Error>>
async fn append( &self, events: &[Event], condition: Option<&AppendCondition>, ) -> Result<SequencePosition, AppendError<<TraitVariantBlanketType as EventStore>::Error>>
Source§async fn head(
&self,
) -> Result<Option<SequencePosition>, <TraitVariantBlanketType as EventStore>::Error>
async fn head( &self, ) -> Result<Option<SequencePosition>, <TraitVariantBlanketType as EventStore>::Error>
None when it
holds nothing. Read moreSource§async fn contains_event_id(
&self,
id: EventId,
) -> Result<bool, <TraitVariantBlanketType as EventStore>::Error>
async fn contains_event_id( &self, id: EventId, ) -> Result<bool, <TraitVariantBlanketType as EventStore>::Error>
id. Read more