Skip to main content

StateControllerBuilder

Struct StateControllerBuilder 

Source
pub struct StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G = NoGuard>
where ID: AgentId, Op: Debug + Clone + Send + Sync + 'static, StateType: Debug + Send + Sync + 'static, SL: StateLogic<Op, ID, StateType>, Sess: Session<Op, ID>, SP: SnapshotProvider<ID, StateType, Op>, G: OpGuard<Op, ID, StateType>,
{ /* private fields */ }
Expand description

Assembles a StateController from its four components.

All components are required, so they are constructor arguments and build cannot fail:

ⓘ
let (tx, controller) = StateControllerBuilder::new(logic, session, snapshotter, initial_state)
  .command_buffer(64)
  .build();
tokio::spawn(controller.run());

Implementations§

Source§

impl<Op, ID, StateType, SL, Sess, SP> StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, NoGuard>
where ID: AgentId, Op: Debug + Clone + Send + Sync + 'static, StateType: Debug + Send + Sync + 'static, SL: StateLogic<Op, ID, StateType>, Sess: Session<Op, ID>, SP: SnapshotProvider<ID, StateType, Op>,

Source

pub fn new( op_handler: Arc<SL>, session: Arc<Sess>, snapshot_provider: Arc<SP>, initial_state: StateType, ) -> Self

Starts a builder with everything a controller needs.

Source§

impl<Op, ID, StateType, SL, Sess, SP, G> StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G>
where ID: AgentId, Op: Debug + Clone + Send + Sync + 'static, StateType: Debug + Send + Sync + 'static, SL: StateLogic<Op, ID, StateType>, Sess: Session<Op, ID>, SP: SnapshotProvider<ID, StateType, Op>, G: OpGuard<Op, ID, StateType>,

Source

pub fn guard<G2>( self, op_guard: Arc<G2>, ) -> StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G2>
where G2: OpGuard<Op, ID, StateType>,

Sets the OpGuard screening agent ops ahead of StateLogic.

Runs per op with the state read-only. A refused op never reaches the rules, its reply (if any) goes back to the source as a system op and the refusal counts in ControllerStats::ops_refused. System submissions and time steps are never screened. The default is NoGuard.

ⓘ
.guard(Arc::new(GuardFn(screen)))
Source

pub fn snapshot_context_on_join(self, context: Option<SnapshotContext>) -> Self

Sets the SnapshotContext used for the snapshot a joining agent receives.

Defaults to Full. Set a perspective here when clients should join into a named view rather than the whole state:

ⓘ
.snapshot_context_on_join(Some(SnapshotContext::ForPerspective("player".into())))
Source

pub fn command_buffer(self, size: usize) -> Self

Sets the command channel depth (default DEFAULT_COMMAND_BUFFER).

Source

pub fn with_stats(self, stats: Arc<ControllerStats>) -> Self

Writes counters into one the application already holds, instead of the fresh one built by default.

For a process that wants a single reading across several controllers, or one that has to hold the handle before the controller is constructed.

Source

pub fn stats(&self) -> Arc<ControllerStats> ⓘ

The live counters this controller will write into.

Take it before build and keep the Arc: it is readable at any moment from any thread, including while the controller is mid-tick, which a command-based query could not manage. See ControllerStats.

Source

pub fn build( self, ) -> (CommandSender<Op, ID, StateType>, StateController<Op, ID, StateType, SL, Sess, SP, G>)

Builds the controller and the sender used to command it.

Source§

impl<Op, ID, StateType, SL, Sess> StateControllerBuilder<Op, ID, StateType, SL, Sess, NoSnapshots>
where ID: AgentId, Op: Debug + Clone + Send + Sync + 'static, StateType: Debug + Send + Sync + 'static, SL: StateLogic<Op, ID, StateType>, Sess: Session<Op, ID>,

Source

pub fn without_snapshots( op_handler: Arc<SL>, session: Arc<Sess>, initial_state: StateType, ) -> Self

Starts a builder for an application where joining carries no catch-up.

For a chat relay, an event log or a client that rebuilds from the op stream, which would otherwise each write a SnapshotProvider returning Ok(None). Everything else about the controller is unchanged, including SendSnapshots, which becomes a request that sends nothing.

ⓘ
let (tx, controller) = StateControllerBuilder::without_snapshots(logic, session, state).build();

Auto Trait Implementations§

§

impl<Op, ID, StateType, SL, Sess, SP, G = NoGuard> !RefUnwindSafe for StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G>

§

impl<Op, ID, StateType, SL, Sess, SP, G = NoGuard> !UnwindSafe for StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G>

§

impl<Op, ID, StateType, SL, Sess, SP, G> Freeze for StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G>
where Arc<SL>: Freeze, Arc<Sess>: Freeze, Arc<SP>: Freeze, Arc<G>: Freeze, StateType: Freeze, PhantomData<fn() -> (Op, ID)>: Freeze,

§

impl<Op, ID, StateType, SL, Sess, SP, G> Send for StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G>
where Arc<SL>: Send, Arc<Sess>: Send, Arc<SP>: Send, Arc<G>: Send, PhantomData<fn() -> (Op, ID)>: Send,

§

impl<Op, ID, StateType, SL, Sess, SP, G> Sync for StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G>
where Arc<SL>: Sync, Arc<Sess>: Sync, Arc<SP>: Sync, Arc<G>: Sync, PhantomData<fn() -> (Op, ID)>: Sync,

§

impl<Op, ID, StateType, SL, Sess, SP, G> Unpin for StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G>
where Arc<SL>: Unpin, Arc<Sess>: Unpin, Arc<SP>: Unpin, Arc<G>: Unpin, StateType: Unpin, PhantomData<fn() -> (Op, ID)>: Unpin,

§

impl<Op, ID, StateType, SL, Sess, SP, G> UnsafeUnpin for StateControllerBuilder<Op, ID, StateType, SL, Sess, SP, G>

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