Skip to main content

RepositoryBuilder

Struct RepositoryBuilder 

Source
pub struct RepositoryBuilder<S, C, A, Snap = NoSnapshot, M = ()> { /* private fields */ }
Expand description

Builder for creating an EventStore facade from a Store.

Obtained via Store::repository(), which always starts the builder with NeedsCodec. Set a codec with .codec() or, under the json feature, .json().

Upcasting is not configured here — the resulting facade ships with the no-upcaster Repository::load / save path. For schema evolution, use the facade’s inherent load_with / save_with methods after build().

§Example

let store = Store::new(backend);

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

// Custom codec:
let repo = store.repository::<Order>().codec(MyCodec).build();

// With metadata provider (e.g. HLC stamp, signature bytes):
let repo = store.repository::<Order>().codec(MyCodec).metadata(|v, e, p| Some(...)).build();

// With upcasting (drop to the facade after build):
let repo = store.repository::<Order>().codec(MyCodec).build();
let root = repo.load_with(id, OrderTransforms::upcast).await?;

Implementations§

Source§

impl<S, C, A, Snap, M> RepositoryBuilder<S, C, A, Snap, M>

Source

pub fn codec<NewC>(self, codec: NewC) -> RepositoryBuilder<S, NewC, A, Snap, M>

Replace the codec.

Returns a new builder with the updated codec type, preserving the store, the bound aggregate, any snapshot configuration, and any configured metadata provider.

Source

pub fn metadata<NewM>( self, provider: NewM, ) -> RepositoryBuilder<S, C, A, Snap, NewM>

Set the metadata provider for this facade.

The provider is called once per event on the write path (post-encode) and can return Some(Metadata) to attach to the envelope or None to leave metadata absent. It is infallible; cap errors are handled by the provider at Metadata construction.

Order-independent: may be called before or after .codec(), .snapshot_store(), etc.

Source§

impl<S, C, A, Snap, M> RepositoryBuilder<S, C, A, Snap, M>

Source

pub fn json(self) -> RepositoryBuilder<S, JsonCodec, A, Snap, M>

Use the built-in JsonCodec as this facade’s codec.

Convenience for .codec(JsonCodec::default()). This is additive API: enabling the json feature only adds this method — it never changes Store::repository()’s return type, which is always NeedsCodec regardless of features (issue #211).

Source§

impl<S, C, A, M> RepositoryBuilder<S, C, A, NoSnapshot, M>
where S: RawEventStore, C: Send + Sync + 'static, M: Send + Sync + 'static,

Source

pub fn build(self) -> EventStore<S, C, A, M>

Build an EventStore for aggregate A.

One terminal for any codec: the owning-vs-borrowing distinction is inferred from the codec’s Decode::Output GAT (E or &E, unified via Borrow<E>), not restated at the call site. Requires a configured codec (C: Send + Sync + 'static, which excludes NeedsCodec).

Source§

impl<S, C, A, M> RepositoryBuilder<S, C, A, NoSnapshot, M>

Source

pub fn snapshot_store_json<SS>( self, snapshot_store: SS, ) -> RepositoryBuilder<S, C, A, WithSnapshot<CodecSnapshotStore<SS, JsonCodec>, EveryNEvents>, M>

Configure a snapshot store from a byte-level store, wrapping it in the built-in JsonCodec.

Accepts a byte-level SnapshotStore<Vec<u8>, Version> and wraps it in CodecSnapshotStore with JsonCodec. This is the snapshot-json convenience for .snapshot_store() (which takes an already-typed store); enabling snapshot-json adds this method without altering snapshot_store()’s signature — feature-additivity (issue #211).

Pre-fills:

Override any default with .snapshot_trigger(), etc.

§Panics

Cannot panic — the internal expect is on a compile-time constant.

Source§

impl<S, C, A, M> RepositoryBuilder<S, C, A, NoSnapshot, M>

Source

pub fn snapshot_store<SS>( self, snapshot_store: SS, ) -> RepositoryBuilder<S, C, A, WithSnapshot<SS, EveryNEvents>, M>

Configure a snapshot store.

Accepts a pre-composed typed SnapshotStore<S, Version>. If your store is byte-level, compose it with CodecSnapshotStore before passing it here — or, under the snapshot-json feature, use the .snapshot_store_json() convenience which wraps a byte-level store in JsonCodec.

This method’s signature is the same in every feature configuration (issue #211): snapshot-json adds snapshot_store_json() rather than changing what snapshot_store() accepts.

Pre-fills:

Override any default with .snapshot_trigger(), etc.

§Panics

Cannot panic — the internal expect is on a compile-time constant.

Source§

impl<S, C, A, SS, T, M> RepositoryBuilder<S, C, A, WithSnapshot<SS, T>, M>

Source

pub fn snapshot_trigger<NewT: PersistTrigger>( self, trigger: NewT, ) -> RepositoryBuilder<S, C, A, WithSnapshot<SS, NewT>, M>

Replace the snapshot trigger.

Source

pub const fn snapshot_schema_version(self, version: NonZeroU32) -> Self

Set the schema version for snapshot invalidation.

Source

pub const fn snapshot_on_read(self, enabled: bool) -> Self

Enable lazy snapshot creation on read (after full replay).

Source§

impl<S, C, A, SS, T, M> RepositoryBuilder<S, C, A, WithSnapshot<SS, T>, M>
where S: RawEventStore, C: Send + Sync + 'static, M: Send + Sync + 'static,

Source

pub fn build(self) -> Snapshotting<EventStore<S, C, A, M>, SS, T>

Build a snapshot-aware EventStore for aggregate A using an owning Codec.

Auto Trait Implementations§

§

impl<S, C, A, Snap, M> Freeze for RepositoryBuilder<S, C, A, Snap, M>
where C: Freeze, Snap: Freeze, M: Freeze,

§

impl<S, C, A, Snap, M> RefUnwindSafe for RepositoryBuilder<S, C, A, Snap, M>

§

impl<S, C, A, Snap, M> Send for RepositoryBuilder<S, C, A, Snap, M>
where C: Send, Snap: Send, M: Send, S: Sync + Send,

§

impl<S, C, A, Snap, M> Sync for RepositoryBuilder<S, C, A, Snap, M>
where C: Sync, Snap: Sync, M: Sync, S: Sync + Send,

§

impl<S, C, A, Snap, M> Unpin for RepositoryBuilder<S, C, A, Snap, M>
where C: Unpin, Snap: Unpin, M: Unpin,

§

impl<S, C, A, Snap, M> UnsafeUnpin for RepositoryBuilder<S, C, A, Snap, M>
where C: UnsafeUnpin, Snap: UnsafeUnpin, M: UnsafeUnpin,

§

impl<S, C, A, Snap, M> UnwindSafe for RepositoryBuilder<S, C, A, Snap, M>

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> 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, 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