pub struct SimulationView<'a> { /* private fields */ }Implementations§
Source§impl SimulationView<'_>
impl SimulationView<'_>
pub const fn time(&self) -> SimTime
Sourcepub fn army(&self, id: ArmyId) -> Result<Option<&Army>, CanwuError>
pub fn army(&self, id: ArmyId) -> Result<Option<&Army>, CanwuError>
Examples found in repository?
11fn set_stance(
12 view: &SimulationView<'_>,
13 context: &CommandContext,
14 payload: &Value,
15) -> Result<Vec<SystemDirective>, CanwuError> {
16 let army = ArmyId::new(
17 payload
18 .get("army")
19 .and_then(Value::as_u64)
20 .expect("payload was validated before the handler ran"),
21 );
22 let Some(army_state) = view.army(army)? else {
23 return Err(CanwuError::new(
24 ErrorCode::ArmyNotFound,
25 format!("army {army} was not found"),
26 ));
27 };
28 if context.issuer != Issuer::Actor(army_state.commander) {
29 return Err(CanwuError::new(
30 ErrorCode::InvalidAuthority,
31 "only the army commander may set its stance",
32 ));
33 }
34 Ok(vec![SystemDirective::SetComponent {
35 state: StateKey::new("military", "stance"),
36 entity: EntityRef::Army(army),
37 component: "stance".to_owned(),
38 value: payload["stance"].clone(),
39 summary: format!("Army {army} changed stance"),
40 }])
41}pub fn person(&self, id: PersonId) -> Result<Option<&Person>, CanwuError>
pub fn government( &self, id: GovernmentId, ) -> Result<Option<&Government>, CanwuError>
pub fn territory( &self, id: TerritoryId, ) -> Result<Option<&Territory>, CanwuError>
pub fn route(&self, id: RouteId) -> Result<Option<&Route>, CanwuError>
pub fn actor_knowledge( &self, actor: PersonId, ) -> Result<Option<&ActorKnowledge>, CanwuError>
Sourcepub fn knowledge_records(
&self,
holder: KnowledgeHolderRef,
query: &KnowledgeQuery,
) -> Result<KnowledgeQueryResult, CanwuError>
pub fn knowledge_records( &self, holder: KnowledgeHolderRef, query: &KnowledgeQuery, ) -> Result<KnowledgeQueryResult, CanwuError>
Queries holder-relative records for an omniscient plugin system.
This enforces the declared canwu.core.knowledge read and returns an
owned projection. It is not an actor-facing authorization API.
Sourcepub fn command(
&self,
id: CommandId,
) -> Result<Option<&CommandRecord>, CanwuError>
pub fn command( &self, id: CommandId, ) -> Result<Option<&CommandRecord>, CanwuError>
Resolves an exact command ID from the retained runtime journal in O(1).
An archived command remains valid identity evidence, but its payload is
no longer available through this view: lookup returns
ErrorCode::EvidenceContentUnavailable. None means the ID has
neither retained content nor a committed archive receipt.
Sourcepub fn event(&self, id: EventId) -> Result<Option<&SimEvent>, CanwuError>
pub fn event(&self, id: EventId) -> Result<Option<&SimEvent>, CanwuError>
Resolves an exact event ID from the retained runtime journal in O(1).
An archived event remains valid identity evidence, but its payload is
no longer available through this view: lookup returns
ErrorCode::EvidenceContentUnavailable. None means the ID has
neither retained content nor a committed archive receipt.
pub fn ingress( &self, id: IngressId, ) -> Result<Option<&IngressRecord>, CanwuError>
pub fn domain_record( &self, reference: &DomainRecordRef, ) -> Result<Option<&DomainRecord>, CanwuError>
pub fn typed_domain_record<T>(
&self,
reference: &TypedDomainRecordRef<T>,
) -> Result<Option<&DomainRecord>, CanwuError>where
T: DomainRecordType,
pub fn proposed_domain_record( &self, reference: &DomainRecordRef, ) -> Result<Option<&DomainRecord>, CanwuError>
pub fn proposed_typed_domain_record<T>(
&self,
reference: &TypedDomainRecordRef<T>,
) -> Result<Option<&DomainRecord>, CanwuError>where
T: DomainRecordType,
Sourcepub fn proposed_domain_record_version(
&self,
reference: &DomainRecordRef,
) -> Result<Option<DomainRecordVersionRef>, CanwuError>
pub fn proposed_domain_record_version( &self, reference: &DomainRecordRef, ) -> Result<Option<DomainRecordVersionRef>, CanwuError>
Returns the exact evidence reference assigned to a domain-record version proposed earlier in the current boundary.
Sourcepub fn domain_record_version_evidence_exists(
&self,
reference: &DomainRecordVersionRef,
) -> Result<bool, CanwuError>
pub fn domain_record_version_evidence_exists( &self, reference: &DomainRecordVersionRef, ) -> Result<bool, CanwuError>
Returns whether an exact domain-record version reference is valid at this proposal-visible cut.
This validates both the record identity/version and its establishment source. Earlier same-boundary proposals are considered before retained or archived runtime evidence.
Sourcepub fn domain_records_of_kind(
&self,
kind: &DomainRecordKind,
limit: usize,
) -> Result<Vec<DomainRecord>, CanwuError>
pub fn domain_records_of_kind( &self, kind: &DomainRecordKind, limit: usize, ) -> Result<Vec<DomainRecord>, CanwuError>
Returns a bounded, deterministic projection of records of one kind.
Same-boundary overlays take precedence over current state. Records are ordered by their canonical reference, so result order is replay stable.
Sourcepub fn domain_records_of_kind_after(
&self,
kind: &DomainRecordKind,
after: Option<&DomainRecordRef>,
limit: usize,
) -> Result<Vec<DomainRecord>, CanwuError>
pub fn domain_records_of_kind_after( &self, kind: &DomainRecordKind, after: Option<&DomainRecordRef>, limit: usize, ) -> Result<Vec<DomainRecord>, CanwuError>
Returns one bounded deterministic page of records after a canonical record-reference cursor.
The cursor is exclusive and must name the same kind. This keeps plugin
scans bounded without imposing a 10,000-record lifetime ceiling on a
domain kind. Same-boundary overlays retain the same precedence as
Self::domain_records_of_kind.
Sourcepub fn knowledge_changes_by_correlation(
&self,
plugin: &str,
producer_correlation: &str,
) -> Result<Vec<BoundaryKnowledgeChange>, CanwuError>
pub fn knowledge_changes_by_correlation( &self, plugin: &str, producer_correlation: &str, ) -> Result<Vec<BoundaryKnowledgeChange>, CanwuError>
Finds committed knowledge changes produced with an exact correlation.
This supports next-boundary operation finalization without granting a plugin unrestricted access to unrelated knowledge payloads.
Sourcepub fn knowledge_changes_by_correlation_prefix(
&self,
plugin: &str,
producer_correlation_prefix: &str,
) -> Result<Vec<BoundaryKnowledgeChange>, CanwuError>
pub fn knowledge_changes_by_correlation_prefix( &self, plugin: &str, producer_correlation_prefix: &str, ) -> Result<Vec<BoundaryKnowledgeChange>, CanwuError>
Finds committed knowledge changes whose producer correlation begins with a deterministic operation prefix.
The prefix remains plugin-scoped. This is intended for bounded multi-holder operation finalization where every holder batch must keep a unique full correlation value.
Sourcepub fn reservation(
&self,
reservation: &ReservationRef,
) -> Result<Option<&ReservationAllocation>, CanwuError>
pub fn reservation( &self, reservation: &ReservationRef, ) -> Result<Option<&ReservationAllocation>, CanwuError>
Examples found in repository?
48fn apply_grain(
49 view: &SimulationView<'_>,
50 _context: &BoundaryContext,
51) -> Result<BoundaryProposal, CanwuError> {
52 let reservation = ReservationRef::new("example-demand", "request", "daily-grain");
53 let allocation = view.reservation(&reservation)?.ok_or_else(|| {
54 CanwuError::new(
55 ErrorCode::InvalidBoundary,
56 "the declared grain reservation did not produce allocation evidence",
57 )
58 })?;
59 let territory = EntityRef::Territory(TerritoryId::new(1));
60 Ok(BoundaryProposal {
61 directives: vec![
62 BoundaryDirective::SetComponent {
63 state: StateKey::new("garrison", "grain"),
64 entity: territory.clone(),
65 component: "daily_grant".to_owned(),
66 value: Value::from(allocation.granted),
67 summary: format!(
68 "Granted {} grain to the western garrison",
69 allocation.granted
70 ),
71 },
72 BoundaryDirective::Emit {
73 event_type: "grain_allocated".to_owned(),
74 summary: "The daily grain allocation settled".to_owned(),
75 affected: vec![territory],
76 },
77 ],
78 ..BoundaryProposal::default()
79 })
80}