uor-foundation 0.2.0

UOR Foundation — typed Rust traits for the complete ontology. Import and implement.
Documentation
// @generated by uor-crate from uor-ontology — do not edit manually

//! `effect/` namespace — Typed endomorphisms on state:Context classified by site target. Formalizes what reduction guard-effect pairs do to the site budget..
//!
//! Space: Kernel

use crate::Primitives;

/// A typed endomorphism on state:Context. Maps one site-budget configuration to another. The atomic unit of state mutation in the kernel.
pub trait Effect<P: Primitives> {
    /// Associated type for `EffectTarget`.
    type EffectTarget: EffectTarget<P>;
    /// The site coordinates this effect touches.
    fn effect_target(&self) -> &Self::EffectTarget;
    /// Associated type for `Context`.
    type Context: crate::user::state::Context<P>;
    /// The context before effect application.
    fn pre_context(&self) -> &Self::Context;
    /// The context after effect application.
    fn post_context(&self) -> &Self::Context;
    /// Change in freeRank: −1 for PinningEffect, +1 for UnbindingEffect, 0 for PhaseEffect.
    fn free_rank_delta(&self) -> P::Integer;
    /// Position within a CompositeEffect sequence.
    fn composite_index(&self) -> P::NonNegativeInteger;
    /// Computed: true iff effectTargets are disjoint with the compared effect. Derived from DisjointnessWitness existence.
    fn is_commutative_with(&self) -> P::Boolean;
}

/// An effect that has a well-defined inverse. PinningEffect and PhaseEffect are reversible; ExternalEffect and CompositeEffect are not in general.
pub trait ReversibleEffect<P: Primitives>: Effect<P> {}

/// Pins a single free site to a definite value. Decrements freeRank by exactly 1. The effect produced by constraint resolution.
pub trait PinningEffect<P: Primitives>: ReversibleEffect<P> {}

/// Releases a pinned site back to free state. Increments freeRank by exactly 1. The effect produced by session boundary reset.
pub trait UnbindingEffect<P: Primitives>: Effect<P> {}

/// Rotates the reduction phase angle by Ω^k. Does not alter the site budget. The effect produced by reduction step transitions.
pub trait PhaseEffect<P: Primitives>: ReversibleEffect<P> {
    /// The phase rotation applied, expressed as Ω^k.
    fn phase_angle_delta(&self) -> P::Decimal;
}

/// An ordered sequence of effects applied atomically. The composition E₁ ; E₂ applies E₁ then E₂.
pub trait CompositeEffect<P: Primitives>: Effect<P> {
    /// Associated type for `Effect`.
    type Effect: Effect<P>;
    /// The first effect in the composite sequence.
    fn composite_head(&self) -> &Self::Effect;
    /// Subsequent effects in the composite sequence (ordered by effect:compositeIndex).
    fn composite_tail(&self) -> &[Self::Effect];
}

/// An opaque effect declared by a Prism implementation. The kernel treats it as a site-budget transformation satisfying the declared commutation contract. Must carry an effect:externalEffectShape linking to a conformance:EffectShape.
pub trait ExternalEffect<P: Primitives>: Effect<P> {
    /// Associated type for `EffectShape`.
    type EffectShape: crate::bridge::conformance_::EffectShape<P>;
    /// The conformance shape that this external effect satisfies.
    fn external_effect_shape(&self) -> &Self::EffectShape;
}

/// The set of site coordinates that an effect reads or writes. Determines commutation.
pub trait EffectTarget<P: Primitives> {
    /// Associated type for `SiteIndex`.
    type SiteIndex: crate::bridge::partition::SiteIndex<P>;
    /// The individual site coordinates in this target set.
    fn target_sites(&self) -> &[Self::SiteIndex];
    /// Number of site coordinates in this target set.
    fn target_cardinality(&self) -> P::NonNegativeInteger;
}

/// A certificate that two EffectTargets have empty intersection, enabling commutative reordering.
pub trait DisjointnessWitness<P: Primitives> {
    /// Associated type for `EffectTarget`.
    type EffectTarget: EffectTarget<P>;
    /// The left target in the disjointness claim.
    fn disjointness_left(&self) -> &Self::EffectTarget;
    /// The right target in the disjointness claim.
    fn disjointness_right(&self) -> &Self::EffectTarget;
}