pub struct ContextState { /* private fields */ }Expand description
The shared context for a Converge job.
Agents receive &dyn converge_pack::Context (immutable) during execution.
Only the engine holds &mut Context during the merge phase.
Implementations§
Source§impl ContextState
impl ContextState
Sourcepub fn new() -> ContextState
pub fn new() -> ContextState
Creates a new empty context.
Sourcepub fn get(&self, key: ContextKey) -> &[Fact]
pub fn get(&self, key: ContextKey) -> &[Fact]
Returns all facts for a given key.
Sourcepub fn has(&self, key: ContextKey) -> bool
pub fn has(&self, key: ContextKey) -> bool
Returns true if there are any facts for the given key.
Sourcepub fn dirty_keys(&self) -> &[ContextKey]
pub fn dirty_keys(&self) -> &[ContextKey]
Returns keys that changed in the last merge cycle.
Sourcepub fn all_keys(&self) -> Vec<ContextKey>
pub fn all_keys(&self) -> Vec<ContextKey>
Returns all keys that currently have facts in the context.
Sourcepub fn has_pending_proposals(&self) -> bool
pub fn has_pending_proposals(&self) -> bool
Returns true if any staged proposals are pending promotion.
Sourcepub fn clear_dirty(&mut self)
pub fn clear_dirty(&mut self)
Clears the dirty key tracker (called at start of each cycle).
Sourcepub fn add_proposal(
&mut self,
proposal: ProposedFact,
) -> Result<bool, ConvergeError>
pub fn add_proposal( &mut self, proposal: ProposedFact, ) -> Result<bool, ConvergeError>
Stages a proposal for engine validation/promotion.
Returns Ok(true) if the proposal was new.
Returns Ok(false) if an identical proposal is already pending.
Sourcepub fn add_input(
&mut self,
key: ContextKey,
id: impl Into<ProposalId>,
content: impl Into<String>,
) -> Result<bool, ConvergeError>
pub fn add_input( &mut self, key: ContextKey, id: impl Into<ProposalId>, content: impl Into<String>, ) -> Result<bool, ConvergeError>
Stages external input as a proposal to be governed by the engine.
Sourcepub fn add_input_with_provenance(
&mut self,
key: ContextKey,
id: impl Into<ProposalId>,
content: impl Into<String>,
provenance: impl Into<String>,
) -> Result<bool, ConvergeError>
pub fn add_input_with_provenance( &mut self, key: ContextKey, id: impl Into<ProposalId>, content: impl Into<String>, provenance: impl Into<String>, ) -> Result<bool, ConvergeError>
Stages external input with explicit provenance.
Trait Implementations§
Source§impl Clone for ContextState
impl Clone for ContextState
Source§fn clone(&self) -> ContextState
fn clone(&self) -> ContextState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Context for ContextState
Implement the converge-pack Context trait for the concrete Context struct.
This allows agents to use &dyn converge_pack::Context.
impl Context for ContextState
Implement the converge-pack Context trait for the concrete Context struct.
This allows agents to use &dyn converge_pack::Context.