Module obligation
Expand description
Completion obligations on top of Rust’s affine ownership.
Linear type systems require each resource to be used exactly once. They forbid
implicit duplication (contraction) and discarding (weakening). Affine type
systems allow discarding, so a resource may be used at most once. Rust’s move
semantics for non-Copy values are affine in this sense: moving transfers
ownership, but leaving scope without calling commit or close is legal.
used 0 times used once used twice
affine (`!Copy`) ok (drop/forget) ok compile error
obligation runtime error ok compile error
linear (ideal) compile error ok compile errorObligation owns work that must finish before it is dropped. Calling
complete(context).await runs that work’s Execute implementation. There
is no separate call to mark it complete, no mutable access to replace the work
and no way to substitute an unrelated future.
Work types implement these traits beside their own code. This module only
manages the guard. Implementations decide what counts as finished and must
handle failures before returning. The compiler ties completion to those
implementations but cannot verify that they do the work correctly.
A synchronous commit can use TryComplete. Rejection returns the still-armed
obligation. Transfer converts work to its next form without completing it.
For example, rollback can turn a reservation into cleanup work, keeping the
same guard until cleanup and any required fallback finish, even if they fail.
Queuing cleanup is not enough.
Merging batches moves the work before disarming the donor’s guard.
The guard reports unfinished work when it is dropped, including when
cancellation drops an execution future before its first poll or during an
await. It does not run cleanup. This is a runtime check: #[must_use] cannot
prove that work finishes, std::mem::forget can bypass the destructor and
process termination can skip it too.
See Asynchronous clean-up for the connection between linear types, explicit cleanup and cancellation.
Structs§
- Obligation
- Work that must be completed, with a guard that reports an unfinished drop.
Traits§
- Execute
- The asynchronous operation that completes the work.
- Transfer
- Converts unfinished work to its next form, such as a reservation to cleanup.
- TryComplete
- A synchronous state change that returns the work if it is rejected.
- Work
- Work whose completion rules are defined by its type.