Struct OffsetMap

Source
pub struct OffsetMap(/* private fields */);
Expand description

Multi-dimensional cursor for event streams: an OffsetMap describes the set of events given by the event streams of each included source up to the associated Offset.

All stream delivery modes supported by the Event Service respect the order of offsets of the events published by each single AX node. This order is consistent with the Lamport timestamp order because both numbers are assigned to published events in strictly monotonically increasing fashion, i.e. greater offset implies greater Lamport timestamp and vice versa.

Note that if the OffsetMap contains offset 42 for StreamId "abc.0" it denotes that events with offsets 0 through 42 (inclusive) are included within the OffsetMap.

A common usage pattern is to store the OffsetMap describing the events already consumed from an event stream together with the computation results from processing those events (preferably within the same database transaction, if applicable). When restarting the process, this OffsetMap can be read and the stream can be resumed from where the process left off previously.

§Arithmetics

OffsetMap has a partial order: when the set of events described by one is a strict subset of the set of events described by another, then one is said to be smaller than the other. It may be that one OffsetMap contains events that the other does not and vice versa, in which case they are incomparable (partial_cmp will return None).

An event may be added into an OffsetMap to denote that from the event’s stream all events up to this one shall be included in the OffsetMap.

The difference of two offset maps yields the number of events contained within the first but not within the second one (i.e. it counts the size of the difference set).

§Deserialization

An OffsetMap only contains valid offsets (non-negative numbers), but during deserialization negative values are tolerated and ignored. This is to keep compatibility with previously documented API endpoints.

Implementations§

Source§

impl OffsetMap

Source

pub fn empty() -> Self

The empty OffsetMap is equivalent to the beginning of time, it does not contain any event.

Source

pub fn is_empty(&self) -> bool

Returns true if this OffsetMap does not contain any events

Source

pub fn contains<T>(&self, event: &Event<T>) -> bool

Check whether the given Event’s offset and source ID are contained within this OffsetMap.

Source

pub fn contains_stream(&self, stream: &StreamId) -> bool

Check whether the given stream contributes to the set of events in this OffsetMap

Source

pub fn offset(&self, stream: impl Into<StreamId>) -> OffsetOrMin

Retrieve the offset stored for the given source

The returned value is OffsetOrMin::MIN if nothing is stored for the given source.

Source

pub fn get(&self, stream: impl Into<StreamId>) -> Option<Offset>

Retrieves the offset stored for the given source

Source

pub fn size(&self) -> u64

Counts the number of offsets spanned by this OffsetMap.

Source

pub fn union_with(&mut self, other: &OffsetMap)

Merge the other OffsetMap into this one, taking the union of their event sets.

Source

pub fn union(&self, other: &OffsetMap) -> OffsetMap

Compute the union of two sets of events described by OffsetMaps

Source

pub fn intersection_with(&mut self, other: &OffsetMap)

Compute the intersection of two sets of events described by OffsetMaps

Source

pub fn intersection(&self, other: &OffsetMap) -> OffsetMap

Compute the intersection of two sets of events described by OffsetMaps

Source

pub fn into_inner(self) -> BTreeMap<StreamId, Offset>

Source

pub fn streams(&self) -> impl Iterator<Item = StreamId> + '_

An iterator over all streams that contribute events to this OffsetMap

Source

pub fn stream_iter(&self) -> impl Iterator<Item = (StreamId, Offset)> + '_

An iterator over all streams that contribute events to this OffsetMap including their offset

Source

pub fn update( &mut self, stream: impl Into<StreamId>, offset: Offset, ) -> Option<OffsetOrMin>

Update entry for source if the given offset is larger than the stored one and return the previous offset for this source

Source

pub fn includes( &self, other: impl IntoIterator<Item = (StreamId, Offset)>, ) -> bool

Trait Implementations§

Source§

impl<T> AddAssign<&Event<T>> for OffsetMap

Source§

fn add_assign(&mut self, other: &Event<T>)

Performs the += operation. Read more
Source§

impl AddAssign<&EventKey> for OffsetMap

Source§

fn add_assign(&mut self, other: &EventKey)

Performs the += operation. Read more
Source§

impl AsRef<BTreeMap<StreamId, Offset>> for OffsetMap

Source§

fn as_ref(&self) -> &BTreeMap<StreamId, Offset>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl BitAnd for &OffsetMap

Source§

type Output = OffsetMap

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAnd for OffsetMap

Source§

type Output = OffsetMap

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAndAssign for OffsetMap

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl BitOr for &OffsetMap

Source§

type Output = OffsetMap

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr for OffsetMap

Source§

type Output = OffsetMap

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOrAssign for OffsetMap

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl Clone for OffsetMap

Source§

fn clone(&self) -> OffsetMap

Returns a copy 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 OffsetMap

Source§

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

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

impl Default for OffsetMap

Source§

fn default() -> OffsetMap

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for OffsetMap

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<BTreeMap<StreamId, Offset>> for OffsetMap

Source§

fn from(map: BTreeMap<StreamId, Offset>) -> Self

Converts to this type from the input type.
Source§

impl From<BTreeMap<StreamId, OffsetOrMin>> for OffsetMap

Source§

fn from(map: BTreeMap<StreamId, OffsetOrMin>) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<(StreamId, Offset)> for OffsetMap

Source§

fn from_iter<T: IntoIterator<Item = (StreamId, Offset)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for OffsetMap

Source§

fn eq(&self, other: &OffsetMap) -> 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 PartialOrd for OffsetMap

Source§

fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for OffsetMap

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub<&OffsetMap> for &OffsetMap

Source§

type Output = u64

The resulting type after applying the - operator.
Source§

fn sub(self, other: &OffsetMap) -> u64

Performs the - operation. Read more
Source§

impl Sub for OffsetMap

Source§

type Output = u64

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> u64

Performs the - operation. Read more
Source§

impl<T> SubAssign<&Event<T>> for OffsetMap

Source§

fn sub_assign(&mut self, other: &Event<T>)

Ensure that the given event is no longer contained within this OffsetMap.

Source§

impl SubAssign<&EventKey> for OffsetMap

Source§

fn sub_assign(&mut self, other: &EventKey)

Ensure that the given event is no longer contained within this OffsetMap.

Source§

impl Eq for OffsetMap

Source§

impl StructuralPartialEq for OffsetMap

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> References<RawCodec> for T

Source§

fn references<R, E>(_c: RawCodec, _r: &mut R, _set: &mut E) -> Result<(), Error>
where R: Read, E: Extend<Cid<64>>,

Scrape the references from an impl Read. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,