Skip to main content

Obligation

Struct Obligation 

Source
pub struct Obligation {
    pub id: ObligationId,
    pub obligation_type: ObligationType,
    pub agent: String<32>,
    pub action: String<64>,
    pub object: Option<String<64>>,
    pub state: ObligationState,
    pub created_at: u64,
    pub deadline_ns: Option<u64>,
    pub last_updated: u64,
    pub source: Option<String<128>>,
    pub priority: u8,
}
Expand description

A tracked obligation in the world state.

Fields§

§id: ObligationId§obligation_type: ObligationType

SDL modality.

§agent: String<32>

The agent bearing the obligation.

§action: String<64>

The action the obligation concerns.

§object: Option<String<64>>

Optional object/patient of the action.

§state: ObligationState

Current lifecycle state.

§created_at: u64

Logical time when obligation was created (nanoseconds or counter).

§deadline_ns: Option<u64>

Deadline for satisfaction. None = no deadline (permanent).

§last_updated: u64

Logical time of last state transition.

§source: Option<String<128>>

Policy source citation.

§priority: u8

Priority (higher = more urgent). Used for escalation ordering.

Implementations§

Source§

impl Obligation

Source

pub fn new( id: &str, obligation_type: ObligationType, agent: &str, action: &str, deadline_ns: Option<u64>, created_at: u64, ) -> Obligation

Examples found in repository?
examples/comparison_opa.rs (lines 73-80)
54fn main() {
55    println!("=== URGE side of the OPA comparison ===\n");
56    println!("policy expression: {POLICY}\n");
57
58    let pipeline = GovernancePipeline::new(PipelineConfig::healthcare());
59
60    // Case 1: everything in order — same PERMIT OPA gives.
61    evaluate(&pipeline, true, true);
62
63    // Case 2: review missing. OPA says deny. URGE says deny AND reports the
64    // cross-paradigm finding: the temporal constraint is violated while the
65    // deontic obligation is active — a contradiction, not just a false.
66    evaluate(&pipeline, true, false);
67
68    // Part 2 — what OPA has no vocabulary for at all: the review is an
69    // obligation with a deadline, tracked across time.
70    println!("=== Obligation lifecycle (no OPA equivalent) ===\n");
71    let mut mgr = ObligationManager::new();
72    mgr.register(
73        Obligation::new(
74            "review-P123",
75            ObligationType::Obligatory,
76            "payment-agent",
77            "complete_review",
78            Some(1000), // deadline at t=1000
79            0,
80        ),
81        0,
82    );
83    println!("t=0     obligation registered: complete_review, deadline t=1000");
84    println!(
85        "        active={} violated={}",
86        mgr.active_count(),
87        mgr.violated_count()
88    );
89
90    let violations = mgr.process(ObligationEvent::TimeTick { now: 2000 });
91    println!("t=2000  time tick — deadline exceeded, review never happened");
92    for v in &violations {
93        println!("        VIOLATION EVENT: {v:?}");
94    }
95    println!(
96        "        active={} violated={}",
97        mgr.active_count(),
98        mgr.violated_count()
99    );
100}
Source

pub fn activate(&mut self, now: u64)

Transition to Active.

Source

pub fn satisfy(&mut self, now: u64)

Mark as satisfied (action performed).

Source

pub fn check_deadline(&mut self, now: u64) -> bool

Check deadline and transition to Violated if exceeded. Returns true if a violation was newly detected.

Source

pub fn waive(&mut self, now: u64)

Waive this obligation.

Source

pub fn summary(&self) -> String<128>

Human-readable summary for audit logs.

Trait Implementations§

Source§

impl Clone for Obligation

Source§

fn clone(&self) -> Obligation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Obligation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.