Skip to main content

Expected

Enum Expected 

Source
#[non_exhaustive]
pub enum Expected { Unwritten, Seq(u64), }
Expand description

What a caller believes a stream’s head to be, as of when it last looked.

A named type rather than an Option<u64> or a zero sentinel. The two cases are not “some head” and “no head” — they are two different claims, and the empty one is the one everybody gets wrong. Rails Event Store spells it -1, others spell it 0, and both produce off-by-one bug reports; Equinox hides the number entirely rather than let it into domain code. Naming the empty case is the mitigation available to a store that has to expose it at all.

§Two variants are the surface

Stores that run as a service tend to offer four: these two, an Any that checks nothing, and a StreamExists that checks only that the stream was written to. Any is spelled here by not calling EventStore::append_expecting. StreamExists is absent on purpose. KurrentDB added it so an append could refuse a soft-deleted stream — a stream that was written, then marked gone. That third state has nothing to stand on here: the trait has no delete, retention leaves the counter alone, and a stream has either been written or it has not. Past the existence check StreamExists is Any, so it also adds nothing to concurrency that Expected::Seq does not already give.

The question it is usually reached for — “did the command that creates this stream run?” — is a fact about the domain, and it goes where domain facts go: a key under meta on the creating event, read through crate::log::Filter. See crate::event on why lifecycle lives there.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Unwritten

Nothing has ever been appended to this stream.

Not the same as “the stream reads empty”. Retention can empty a stream whose counter stands at 50, and a caller that meant “this is a new order” must not be told yes about an order that was archived. The check is against what the stream’s counter records, not against the rows that survive.

§

Seq(u64)

The last event appended to this stream has this seq.

A seq, not a crate::position::Position: the claim is about one stream, and the two coordinates have different scopes.

Trait Implementations§

Source§

impl Clone for Expected

Source§

fn clone(&self) -> Expected

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Expected

Source§

impl Debug for Expected

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Expected

Source§

impl PartialEq for Expected

Source§

fn eq(&self, other: &Expected) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Expected

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.