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.
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
impl AppendCondition
Sourcepub fn min(selector: EventSelector, revision: u64) -> AppendCondition
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.
Sourcepub fn max(selector: EventSelector, revision: u64) -> AppendCondition
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).
Sourcepub fn range(selector: EventSelector, range: Range) -> AppendCondition
pub fn range(selector: EventSelector, range: Range) -> AppendCondition
Create a RANGE condition (events must have revision within range).
Sourcepub fn fail_if_events_match(selector: EventSelector) -> AppendCondition
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);Sourcepub fn must_not_exist(selector: EventSelector) -> AppendCondition
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);Sourcepub fn must_exist(selector: EventSelector) -> AppendCondition
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);Sourcepub fn at_revision(
selector: EventSelector,
revision: u64,
) -> Result<AppendCondition, ConstraintError>
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();Sourcepub fn unchanged_since(
selector: EventSelector,
last_seen_revision: u64,
) -> AppendCondition
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);Sourcepub fn selector(&self) -> &EventSelector
pub fn selector(&self) -> &EventSelector
Get the selector for this condition.
Sourcepub fn min_revision(&self) -> Option<u64>
pub fn min_revision(&self) -> Option<u64>
Get the minimum revision bound, if any.
Sourcepub fn max_revision(&self) -> Option<u64>
pub fn max_revision(&self) -> Option<u64>
Get the maximum revision bound, if any.
Sourcepub fn combine(
&self,
rhs: &AppendCondition,
) -> Result<AppendCondition, ConstraintError>
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
impl Clone for AppendCondition
Source§fn clone(&self) -> AppendCondition
fn clone(&self) -> AppendCondition
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AppendCondition
impl Debug for AppendCondition
Source§impl From<AppendCondition> for AppendCondition
impl From<AppendCondition> for AppendCondition
Source§fn from(condition: AppendCondition) -> Self
fn from(condition: AppendCondition) -> Self
Source§impl Hash for AppendCondition
impl Hash for AppendCondition
Source§impl PartialEq for AppendCondition
impl PartialEq for AppendCondition
Source§impl TryFrom<AppendCondition> for AppendCondition
impl TryFrom<AppendCondition> for AppendCondition
impl Eq for AppendCondition
impl StructuralPartialEq for AppendCondition
Auto Trait Implementations§
impl Freeze for AppendCondition
impl RefUnwindSafe for AppendCondition
impl Send for AppendCondition
impl Sync for AppendCondition
impl Unpin for AppendCondition
impl UnwindSafe for AppendCondition
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request