AppendCondition

Enum AppendCondition 

Source
pub enum AppendCondition {
    Min(EventSelector, u64),
    Max(EventSelector, u64),
    Range(EventSelector, Range),
}
Expand description

An append condition for a batch transaction (DCB spec: “Append Condition”).

Append conditions ensure that events matching a selector have revision numbers within specified bounds at the time of transaction.

See: https://dcb.events/specification/

Variants§

§

Min(EventSelector, u64)

Events matching selector must have revision >= min.

§

Max(EventSelector, u64)

Events matching selector must have revision <= max.

§

Range(EventSelector, Range)

Events matching selector must have revision within range.

Implementations§

Source§

impl AppendCondition

Source

pub fn min(selector: EventSelector, revision: u64) -> AppendCondition

Create a MIN condition (events must have revision >= min).

Use this when you want to ensure events exist (min=1) or have been updated to at least a certain revision.

Source

pub fn max(selector: EventSelector, revision: u64) -> AppendCondition

Create a MAX condition (events must have revision <= max).

Use this when you want to ensure events don’t exist yet (max=0) or haven’t changed beyond a known revision (optimistic concurrency).

Source

pub fn range(selector: EventSelector, range: Range) -> AppendCondition

Create a RANGE condition (events must have revision within range).

Source

pub fn fail_if_events_match(selector: EventSelector) -> AppendCondition

Create a condition that fails if any events match the selector.

This is the core DCB pattern for ensuring uniqueness. It’s equivalent to max(selector, 0).

See: https://dcb.events/specification/

§Example
use evidentsource_core::domain::{AppendCondition, EventSelector};

let selector = EventSelector::stream_equals("my-stream").unwrap();
let condition = AppendCondition::fail_if_events_match(selector);
Source

pub fn must_not_exist(selector: EventSelector) -> AppendCondition

Require that no events matching the selector exist.

This is a semantic alias for max(selector, 0). Use this when creating new entities to ensure uniqueness.

§Example
use evidentsource_core::domain::{AppendCondition, EventSelector};

let selector = EventSelector::stream_equals("my-stream").unwrap();
let condition = AppendCondition::must_not_exist(selector);
Source

pub fn must_exist(selector: EventSelector) -> AppendCondition

Require that at least one event matching the selector exists.

This is a semantic alias for min(selector, 1). Use this when updating existing entities to ensure they exist.

§Example
use evidentsource_core::domain::{AppendCondition, EventSelector};

let selector = EventSelector::stream_equals("my-stream").unwrap();
let condition = AppendCondition::must_exist(selector);
Source

pub fn at_revision( selector: EventSelector, revision: u64, ) -> Result<AppendCondition, ConstraintError>

Require events matching the selector to be exactly at a specific revision.

Use this for strict revision checks where you need to ensure the exact state hasn’t changed.

§Errors

Returns ConstraintError::InvalidRange if the revision is invalid for creating a range (this should never happen in practice).

§Example
use evidentsource_core::domain::{AppendCondition, EventSelector};

let selector = EventSelector::stream_equals("my-stream").unwrap();
let condition = AppendCondition::at_revision(selector, 42).unwrap();
Source

pub fn unchanged_since( selector: EventSelector, last_seen_revision: u64, ) -> AppendCondition

Require events matching the selector haven’t changed since a known revision.

This is a semantic alias for max(selector, revision). Use this for optimistic concurrency control where you want to ensure no updates have occurred since you last read the data.

§Example
use evidentsource_core::domain::{AppendCondition, EventSelector};

let selector = EventSelector::stream_equals("my-stream").unwrap();
// Ensure the stream hasn't been modified since revision 42
let condition = AppendCondition::unchanged_since(selector, 42);
Source

pub fn selector(&self) -> &EventSelector

Get the selector for this condition.

Source

pub fn min_revision(&self) -> Option<u64>

Get the minimum revision bound, if any.

Source

pub fn max_revision(&self) -> Option<u64>

Get the maximum revision bound, if any.

Source

pub fn combine( &self, rhs: &AppendCondition, ) -> Result<AppendCondition, ConstraintError>

Combine two conditions into one.

Both conditions must have the same selector. The resulting condition is the union of the bounds (widest range that satisfies both).

§Errors

Returns ConstraintError::IncompatibleSelectors if the conditions have different selectors.

Returns ConstraintError::Conflict if the combined bounds are invalid (e.g., min > max).

Trait Implementations§

Source§

impl Clone for AppendCondition

Source§

fn clone(&self) -> AppendCondition

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for AppendCondition

Source§

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

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

impl From<AppendCondition> for AppendCondition

Source§

fn from(condition: AppendCondition) -> Self

Converts to this type from the input type.
Source§

impl Hash for AppendCondition

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for AppendCondition

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<AppendCondition> for AppendCondition

Source§

type Error = ConversionError

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

fn try_from(proto: AppendCondition) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for AppendCondition

Source§

impl StructuralPartialEq for AppendCondition

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more