Delegation

Struct Delegation 

Source
pub struct Delegation<S: DelegationState> {
    data: DelegationRecord,
    _state: PhantomData<S>,
}
Expand description

A delegation with compile-time state tracking.

The type parameter S indicates the current state of the delegation. Methods are only available in appropriate states:

  • Delegation<Pending>: Can be accepted, rejected, or timeout
  • Delegation<DelegationAccepted>: Can be started or fail
  • Delegation<InProgress>: Can be completed or fail
  • Delegation<DelegationCompleted>: Terminal, has result
  • Delegation<DelegationRejected>: Terminal
  • Delegation<DelegationFailed>: Terminal, has failure reason

Fields§

§data: DelegationRecord§_state: PhantomData<S>

Implementations§

Source§

impl<S: DelegationState> Delegation<S>

Source

pub fn data(&self) -> &DelegationRecord

Access the underlying delegation data (read-only).

Source

pub fn delegation_id(&self) -> DelegationId

Get the delegation ID.

Source

pub fn tenant_id(&self) -> TenantId

Get the tenant ID.

Source

pub fn from_agent_id(&self) -> AgentId

Get the delegating agent ID.

Source

pub fn to_agent_id(&self) -> AgentId

Get the delegate agent ID.

Source

pub fn trajectory_id(&self) -> TrajectoryId

Get the trajectory ID.

Source

pub fn scope_id(&self) -> ScopeId

Get the scope ID.

Source

pub fn task_description(&self) -> &str

Get the task description.

Source

pub fn created_at(&self) -> Timestamp

Get when the delegation was created.

Source

pub fn expected_completion(&self) -> Option<Timestamp>

Get the expected completion time.

Source

pub fn context(&self) -> Option<&Value>

Get the context.

Source

pub fn into_data(self) -> DelegationRecord

Consume and return the underlying data (for serialization).

Source§

impl Delegation<Pending>

Source

pub fn new(data: DelegationRecord) -> Self

Create a new pending delegation.

Source

pub fn accept(self, accepted_at: Timestamp) -> Delegation<DelegationAccepted>

Accept the delegation.

Transitions to Delegation<DelegationAccepted>. Consumes the current delegation.

Source

pub fn reject(self, reason: String) -> Delegation<DelegationRejected>

Reject the delegation.

Transitions to Delegation<DelegationRejected> (terminal state). Consumes the current delegation.

Source

pub fn fail(self, reason: String) -> Delegation<DelegationFailed>

Mark the delegation as failed (e.g., timeout).

Transitions to Delegation<DelegationFailed> (terminal state). Consumes the current delegation.

Source§

impl Delegation<DelegationAccepted>

Source

pub fn accepted_at(&self) -> Timestamp

Get when the delegation was accepted.

Source

pub fn start(self, started_at: Timestamp) -> Delegation<InProgress>

Start working on the delegation.

Transitions to Delegation<InProgress>. Consumes the current delegation.

Source

pub fn fail(self, reason: String) -> Delegation<DelegationFailed>

Mark the delegation as failed before starting.

Transitions to Delegation<DelegationFailed> (terminal state). Consumes the current delegation.

Source§

impl Delegation<InProgress>

Source

pub fn accepted_at(&self) -> Timestamp

Get when the delegation was accepted.

Source

pub fn started_at(&self) -> Timestamp

Get when work started.

Source

pub fn complete( self, completed_at: Timestamp, result: DelegationResult, ) -> Delegation<DelegationCompleted>

Complete the delegation with a result.

Transitions to Delegation<DelegationCompleted> (terminal state). Consumes the current delegation.

Source

pub fn fail(self, reason: String) -> Delegation<DelegationFailed>

Mark the delegation as failed during execution.

Transitions to Delegation<DelegationFailed> (terminal state). Consumes the current delegation.

Source§

impl Delegation<DelegationCompleted>

Source

pub fn accepted_at(&self) -> Timestamp

Get when the delegation was accepted.

Source

pub fn started_at(&self) -> Timestamp

Get when work started.

Source

pub fn completed_at(&self) -> Timestamp

Get when the delegation was completed.

Source

pub fn result(&self) -> &DelegationResult

Get the delegation result.

Source§

impl Delegation<DelegationRejected>

Source

pub fn rejection_reason(&self) -> &str

Get the rejection reason.

Source§

impl Delegation<DelegationFailed>

Source

pub fn failure_reason(&self) -> &str

Get the failure reason.

Trait Implementations§

Source§

impl<S: Clone + DelegationState> Clone for Delegation<S>

Source§

fn clone(&self) -> Delegation<S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<S: Debug + DelegationState> Debug for Delegation<S>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> Freeze for Delegation<S>

§

impl<S> RefUnwindSafe for Delegation<S>
where S: RefUnwindSafe,

§

impl<S> Send for Delegation<S>

§

impl<S> Sync for Delegation<S>

§

impl<S> Unpin for Delegation<S>
where S: Unpin,

§

impl<S> UnwindSafe for Delegation<S>
where S: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.