Skip to main content

Store

Struct Store 

Source
pub struct Store<S> { /* private fields */ }
Expand description

Shared handle to a RawEventStore backend.

Store wraps the backend in an Arc, making it cheap to clone and safe to share across tasks. It carries no codec, upcaster, or aggregate binding — it is just a database handle.

Use repository() to obtain a RepositoryBuilder, then configure a codec and upcaster before calling .build().

§Example

// Open flows left-to-right; `.into_store()` is the de-nested `Store::new`.
let store = FjallStore::builder("path").open()?.into_store();

// One per-aggregate facade per aggregate; the store is the shared substrate.
let orders = store.repository::<Order>().codec(OrderCodec).build();
let users  = store.repository::<User>().codec(UserCodec).build();

Implementations§

Source§

impl<S: RawEventStore> Store<S>

Source

pub fn repository<A>(&self) -> RepositoryBuilder<S, NeedsCodec, A>

Start building a repository facade for aggregate A over this store.

Name the aggregate once here (store.repository::<Order>()); the resulting EventStore<S, C, A> then implements Repository<A> for exactly that A, so load/save infer the aggregate with no per-call annotation. The store itself stays multi-aggregate — mint one facade per aggregate type.

The builder starts with NeedsCodec in every feature configuration — set a codec with .codec(), or, under the json feature, the .json() convenience, before calling .build(). Keeping this return type feature independent is what makes json purely additive (issue #211): a transitive dependency enabling json can never flip this signature out from under code that spelled NeedsCodec.

§Example
let store = Store::new(backend);

// Custom codec:
let orders = store.repository::<Order>().codec(MyCodec).build();
let order = orders.load(id).await?;        // AggregateRoot<Order> — inferred

// Built-in JSON codec (requires the `json` feature):
let orders = store.repository::<Order>().json().build();
Source§

impl<S> Store<S>

Source

pub fn new(raw: S) -> Self

Wrap a raw event store backend in a shared handle.

Source

pub fn raw(&self) -> &S

Borrow the underlying raw store.

The escape hatch for users who need the substrate directly — when the Repository facade’s load / save isn’t flexible enough (e.g. you want to filter, peek, branch, or chain custom combinators during load). Hand the borrowed &S to RawEventStore::read_stream / RawEventStore::append and compose your own chain via futures::StreamExt / futures::TryStreamExt.

Users who just want “load this aggregate” should stay on the facade.

§Example

Substrate-path read: convert the adapter error eagerly and drive a custom fold.

use futures::TryStreamExt;
use mnesis_store::{RawEventStore, Store, StreamKey};

async fn count_events<S: RawEventStore>(
    store: &Store<S>,
    id: &StreamKey,
    from: mnesis::Version,
) -> Result<usize, MyError> {
    let stream = store.raw().read_stream(id, from).await.map_err(MyError::Adapter)?;
    stream.map_err(MyError::Adapter).try_fold(0usize, |acc, _| async move { Ok(acc + 1) }).await
}

Trait Implementations§

Source§

impl<S: AtomicAppend> AtomicAppend for Store<S>

Store<S> forwards AtomicAppend to its inner backend (issue #247). With Store<S> already a RawEventStore, this gives it EventImporter for free via the blanket impl below — so a handle holder can store.import(..) without .raw().

Source§

async fn atomic_append_many( &self, writes: &[PlannedAppend], ) -> Result<Option<Self::AllPosition>, AtomicAppendError<Self::Error>>

Append every write atomically. See the trait contract.
Source§

impl<S> Clone for Store<S>

Source§

fn clone(&self) -> Self

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<S: Debug> Debug for Store<S>

Source§

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

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

impl<S: RawEventStore> RawEventStore for Store<S>

Store<S> is itself a RawEventStore, forwarding every method to its inner backend.

This makes the handle the front door: store.append(..) / read_stream / read_all work directly, and — because EventExporter and EventImporter are blanket-impl’d for every RawEventStore (and RawEventStore + AtomicAppend) — store.export_stream(..) / store.import(..) come for free once Store<S> also forwards StreamLister / AtomicAppend (in the export / import modules). So a Store<S> holder never needs .raw() to back up or restore, and a Store<S> is substitutable wherever a RawEventStore-bounded value is expected. .raw() remains the escape hatch for reaching the concrete &S.

Source§

type Error = <S as RawEventStore>::Error

The error type for store operations.
Source§

type Stream = <S as RawEventStore>::Stream

The stream type for reading events. Read more
Source§

type AllPosition = <S as RawEventStore>::AllPosition

The adapter-defined $all resume position. See AllPosition. Read more
Source§

type AllStream = <S as RawEventStore>::AllStream

The stream type for an all-streams ($all) read. Read more
Source§

async fn append( &self, id: &StreamKey, expected_version: Option<Version>, envelopes: PendingBatch<'_>, ) -> Result<Self::AllPosition, AppendError<Self::Error>>

Append events to a stream with optimistic concurrency. Read more
Source§

async fn read_stream( &self, id: &StreamKey, from: Version, ) -> Result<Self::Stream, Self::Error>

Open a stream of events. Read more
Source§

async fn read_all( &self, from: Option<Self::AllPosition>, ) -> Result<Self::AllStream, Self::Error>

Open a one-shot read over all streams, ordered by AllPosition. Read more
Source§

fn into_store(self) -> Store<Self>
where Self: Sized,

Wrap this backend in a shared Store handle. Read more
Source§

impl<S: StreamLister> StreamLister for Store<S>

Store<S> forwards StreamLister to its inner backend (issue #247), so a handle holder can store.list_streams() without .raw(). EventExporter then applies to Store<S> via the blanket impl above (Store<S> is itself a RawEventStore).

Source§

type StreamList = <S as StreamLister>::StreamList

The stream of stream ids.
Source§

async fn list_streams(&self) -> Result<Self::StreamList, Self::Error>

Open a one-shot stream over every stream id in the store, in no guaranteed order, terminating when exhausted.

Auto Trait Implementations§

§

impl<S> Freeze for Store<S>

§

impl<S> RefUnwindSafe for Store<S>
where S: RefUnwindSafe,

§

impl<S> Send for Store<S>
where S: Sync + Send,

§

impl<S> Sync for Store<S>
where S: Sync + Send,

§

impl<S> Unpin for Store<S>

§

impl<S> UnsafeUnpin for Store<S>

§

impl<S> UnwindSafe for Store<S>
where S: RefUnwindSafe,

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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<S> EventExporter for S
where S: RawEventStore,

Source§

type ExportStream = <S as RawEventStore>::Stream

The stream of exported events. Identical to the read stream — export performs no transform.
Source§

fn export_stream( &self, id: &StreamKey, from: Version, ) -> impl Future<Output = Result<<S as EventExporter>::ExportStream, <S as RawEventStore>::Error>> + Send

Open a per-stream export of stream id, starting at from (inclusive).
Source§

impl<S> EventImporter for S

Source§

async fn import<R>( &self, sections: &[StreamSection], route: R, atomicity: Atomicity, ) -> Result<ImportReport, ImportError<<S as RawEventStore>::Error>>
where R: Fn(&[u8]) -> StreamKey + Send,

Import per-stream sections onto caller-routed target streams. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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> 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