Trait paxakos::applicable::ApplicableTo [−][src]
pub trait ApplicableTo<S: State> {
type Projection: Projection<OutcomeOf<S>>;
fn into_log_entry(self) -> Arc<LogEntryOf<S>>;
}
Expand description
Describes values that may be applied to type S
.
For any given State
implementation there is usually a wide range of
possible operations. These are encoded by its corresponding LogEntry
type,
which commonly contains (or is) an enum value whose variants correspond to
the state’s operations. Different operations usually have different
outcome types, which is why State::Outcome is also commonly an enum.
This presents an ergonomics challenge. Imagine enum MyLogEntry { A, B }
and enum MyOutcome { A(i64), B(bool) }
. When appending a MyLogEntry::A
we’d like to get back an i64
rather than a MyOutcome
. This can be
achieved as follows.
struct A;
impl paxakos::applicable::ApplicableTo<MyState> for A {
type Projection = ProjectionA;
fn into_log_entry(self) -> Arc<MyLogEntry> {
Arc::new(MyLogEntry::A)
}
}
struct ProjectionA;
impl paxakos::applicable::Projection<MyOutcome> for ProjectionA {
type Projected = i64;
fn project(val: MyOutcome) -> Self::Projected {
match val {
MyOutcome::A(i) => i,
_ => panic!("unexpected: {:?}", val)
}
}
}
Associated Types
type Projection: Projection<OutcomeOf<S>>
type Projection: Projection<OutcomeOf<S>>
Projection type, usually a zero-sized type.
Required methods
fn into_log_entry(self) -> Arc<LogEntryOf<S>>
fn into_log_entry(self) -> Arc<LogEntryOf<S>>
Turns this applicable value into a log entry.