Skip to main content

Domain

Struct Domain 

Source
pub struct Domain { /* private fields */ }
Expand description

A domain: a name that scopes its aggregates, commands and events, lowercase by convention (orders) like aggregates, while message types are capitalized (orders.PlaceOrder). Both cases are valid; names are case-sensitive. Types are unique within a domain; elsewhere they are named domain.Type. Cloning gives another handle to the same domain.

Make it with domain: let shop_domain = domain("shop");. A domain remembers the aggregates, read models and reactors created through it, so that an app runs all of them (see crate::Kernable::app); they live as long as the domain does.

Implementations§

Source§

impl Domain

Source

pub fn name(&self) -> &str

The domain’s name, e.g. shop.

Source

pub fn event(&self, event_type: &str, schema: u32) -> EventSchema

Declares that this domain writes event_type events at version schema, with an upcast per older version, and which of their fields the vault keeps; see EventSchema. The domain’s aggregates and listeners use it; other domains’ listeners get it with Listener::with_domain. Types not declared are at version 1.

§Panics

If event_type is qualified or schema is 0.

Source

pub fn command(&self, command_type: &str) -> CommandSchema

Declares which fields of command_type commands the vault keeps (personal, secret); see CommandSchema. Clients that submit them need the domain: kernable.with_domain(&domain).

§Panics

If command_type is qualified.

Source

pub fn query(&self, query_type: &str) -> QuerySchema

Declares what query_type queries are about (see QuerySchema::target): returns the QuerySchema to chain target on. A query type (see crate::query) declares it with target(...) instead. Clients that ask such queries by name need the domain: kernable.with_domain(&domain).

§Panics

If query_type is qualified.

Source

pub fn process(&self, name: &str) -> Process

A business process of this domain named name (fulfilment; qualified shop.fulfilment): add its start and steps to the crate::process::Process it returns. An app of the domain registers it with the kernel (crate::Kernable::app). Example: shop_domain.process("fulfilment").start::<OrderSubmitted>(Start::key("aggregate_id"))....

§Panics

If name is not letters, digits, - and _, or the domain has a process named name already.

Source

pub fn aggregate<S: State>(&self, name: &str, initial: S) -> Aggregate<S>

An aggregate of this domain named name (lowercase by convention, like cart), whose state starts as initial; see Aggregate. Example: let cart_aggregate = shop_domain.aggregate("cart", Cart::default());.

§Panics

If the domain has an aggregate named name already.

Source

pub fn read_model(&self, name: &str) -> Listener

A read model of this domain named name: builds a view from events and answers queries from it; see Listener. Kept in memory and rebuilt from the first event on every start (order 0; Listener::store keeps it in a file instead). Run it with crate::Kernable::listener or in an app. Example: let carts_readmodel = shop_domain.read_model("carts");.

§Panics

If the domain has a read model or reactor named name already.

Source

pub fn reactor(&self, name: &str) -> Listener

A reactor of this domain named name: triggers side effects and follow-up commands; see Listener. It starts at the newest event when it is new, then resumes after the last acknowledged event (order 10). A settling submit from its handler waits for the listeners before it (the read models), not for the reactor itself, which handles one event at a time. Submit follow-ups with ctx.submit and a fixed ID, so a redelivered event does not run the command twice; a rejected one parks the event (see Listener::park_after). Run it with crate::Kernable::listener or in an app.

§Panics

If the domain has a read model or reactor named name already.

Source

pub fn schema_of(&self, event_type: &str) -> u32

The payload version this domain writes event_type events at.

Trait Implementations§

Source§

impl Clone for Domain

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

Auto Trait Implementations§

§

impl Forget for Domain

§

impl Freeze for Domain
where *const ArcInner<DomainInner> is !null: Freeze, PhantomData<ArcInner<DomainInner>>: Freeze,

§

impl Move for Domain

§

impl RefUnwindSafe for Domain

§

impl Send for Domain
where Arc<DomainInner>: Send,

§

impl Sync for Domain
where Arc<DomainInner>: Sync,

§

impl Unpin for Domain
where Arc<DomainInner>: Unpin,

§

impl UnsafeUnpin for Domain
where *const ArcInner<DomainInner> is !null: UnsafeUnpin, PhantomData<ArcInner<DomainInner>>: UnsafeUnpin,

§

impl UnwindSafe for Domain
where Arc<DomainInner>: UnwindSafe,

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> 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<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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