pub enum ProtocolAnnotation {
TimedChoice {
duration: Duration,
},
Priority(u32),
Retry {
max_attempts: u32,
delay: Option<Duration>,
},
Idempotent,
Trace {
label: Option<String>,
},
RuntimeTimeout(Duration),
Heartbeat {
interval: Duration,
on_missing_count: u32,
},
Parallel,
Ordered,
MinResponses(u32),
Custom {
key: String,
value: String,
},
}Expand description
A typed annotation on a protocol statement.
Annotations provide metadata that affects code generation or runtime behavior without changing the core session type semantics.
Variants§
TimedChoice
Timed choice: race an operation against a timeout.
When applied to a Choice, the choosing role races the operation
against the specified duration. If timeout fires first, takes
the TimedOut branch; otherwise takes the OnTime branch.
Priority(u32)
Priority hint for scheduling.
Higher values indicate higher priority. Implementation-specific.
Retry
Retry count for transient failures.
Indicates how many times to retry the operation before failing.
Fields
Idempotent
Mark a statement as idempotent (safe to retry).
Trace
Trace/debug annotation for logging.
RuntimeTimeout(Duration)
Runtime timeout hint (for transport layer, not session type).
Unlike TimedChoice, this doesn’t affect the session type - it’s
purely a hint to the transport layer.
Heartbeat
Heartbeat pattern: sender sends periodic heartbeats, receiver detects absence.
Desugars to a recursive choice where receiver decides liveness.
The runtime uses interval for heartbeat timing and on_missing_count
to determine when to declare the sender dead.
Fields
Parallel
Execute broadcast/collect operations in parallel.
When applied to a message with a wildcard/range destination, sends or receives are executed concurrently rather than sequentially.
Ordered
Preserve strict message ordering.
When applied to a collect operation, messages are returned in the order specified by the role list. This is the default behavior for sequential collect.
MinResponses(u32)
Minimum number of responses required for a collect operation.
When applied to a collect with wildcard/range source, the operation
succeeds once at least min responses are received. Remaining responses
are discarded or handled asynchronously.
Custom
Custom annotation for extensions or unknown types.
Falls back to key-value string pairs for extensibility.
Implementations§
Source§impl ProtocolAnnotation
impl ProtocolAnnotation
Sourcepub fn timed_choice(duration: Duration) -> ProtocolAnnotation
pub fn timed_choice(duration: Duration) -> ProtocolAnnotation
Create a timed choice annotation from a duration.
Sourcepub fn timed_choice_ms(ms: u64) -> ProtocolAnnotation
pub fn timed_choice_ms(ms: u64) -> ProtocolAnnotation
Create a timed choice annotation from milliseconds.
Sourcepub fn priority(value: u32) -> ProtocolAnnotation
pub fn priority(value: u32) -> ProtocolAnnotation
Create a priority annotation.
Sourcepub fn retry(max_attempts: u32) -> ProtocolAnnotation
pub fn retry(max_attempts: u32) -> ProtocolAnnotation
Create a retry annotation with just max attempts.
Sourcepub fn retry_with_delay(
max_attempts: u32,
delay: Duration,
) -> ProtocolAnnotation
pub fn retry_with_delay( max_attempts: u32, delay: Duration, ) -> ProtocolAnnotation
Create a retry annotation with delay between attempts.
Sourcepub fn trace() -> ProtocolAnnotation
pub fn trace() -> ProtocolAnnotation
Create a trace annotation without a label.
Sourcepub fn trace_labeled(label: impl Into<String>) -> ProtocolAnnotation
pub fn trace_labeled(label: impl Into<String>) -> ProtocolAnnotation
Create a trace annotation with a label.
Sourcepub fn runtime_timeout(duration: Duration) -> ProtocolAnnotation
pub fn runtime_timeout(duration: Duration) -> ProtocolAnnotation
Create a runtime timeout annotation.
Sourcepub fn heartbeat(
interval: Duration,
on_missing_count: u32,
) -> ProtocolAnnotation
pub fn heartbeat( interval: Duration, on_missing_count: u32, ) -> ProtocolAnnotation
Create a heartbeat annotation from a duration and missing count.
Sourcepub fn heartbeat_ms(
interval_ms: u64,
on_missing_count: u32,
) -> ProtocolAnnotation
pub fn heartbeat_ms( interval_ms: u64, on_missing_count: u32, ) -> ProtocolAnnotation
Create a heartbeat annotation from milliseconds and missing count.
Sourcepub fn parallel() -> ProtocolAnnotation
pub fn parallel() -> ProtocolAnnotation
Create a parallel annotation.
Sourcepub fn ordered() -> ProtocolAnnotation
pub fn ordered() -> ProtocolAnnotation
Create an ordered annotation.
Sourcepub fn min_responses(min: u32) -> ProtocolAnnotation
pub fn min_responses(min: u32) -> ProtocolAnnotation
Create a min_responses annotation.
Sourcepub fn custom(
key: impl Into<String>,
value: impl Into<String>,
) -> ProtocolAnnotation
pub fn custom( key: impl Into<String>, value: impl Into<String>, ) -> ProtocolAnnotation
Create a custom annotation.
Sourcepub fn is_timed_choice(&self) -> bool
pub fn is_timed_choice(&self) -> bool
Check if this is a timed choice annotation.
Sourcepub fn timed_choice_duration(&self) -> Option<Duration>
pub fn timed_choice_duration(&self) -> Option<Duration>
Get the timed choice duration, if this is a timed choice.
Sourcepub fn is_priority(&self) -> bool
pub fn is_priority(&self) -> bool
Check if this is a priority annotation.
Sourcepub fn priority_value(&self) -> Option<u32>
pub fn priority_value(&self) -> Option<u32>
Get the priority value, if this is a priority annotation.
Sourcepub fn retry_config(&self) -> Option<(u32, Option<Duration>)>
pub fn retry_config(&self) -> Option<(u32, Option<Duration>)>
Get retry parameters, if this is a retry annotation.
Sourcepub fn is_idempotent(&self) -> bool
pub fn is_idempotent(&self) -> bool
Check if this is an idempotent annotation.
Sourcepub fn is_heartbeat(&self) -> bool
pub fn is_heartbeat(&self) -> bool
Check if this is a heartbeat annotation.
Sourcepub fn heartbeat_params(&self) -> Option<(Duration, u32)>
pub fn heartbeat_params(&self) -> Option<(Duration, u32)>
Get the heartbeat parameters, if this is a heartbeat annotation.
Sourcepub fn is_runtime_timeout(&self) -> bool
pub fn is_runtime_timeout(&self) -> bool
Check if this is a runtime timeout annotation.
Sourcepub fn runtime_timeout_duration(&self) -> Option<Duration>
pub fn runtime_timeout_duration(&self) -> Option<Duration>
Get the runtime timeout duration, if this is a runtime timeout annotation.
Sourcepub fn is_parallel(&self) -> bool
pub fn is_parallel(&self) -> bool
Check if this is a parallel annotation.
Sourcepub fn is_ordered(&self) -> bool
pub fn is_ordered(&self) -> bool
Check if this is an ordered annotation.
Sourcepub fn is_min_responses(&self) -> bool
pub fn is_min_responses(&self) -> bool
Check if this is a min_responses annotation.
Sourcepub fn min_responses_value(&self) -> Option<u32>
pub fn min_responses_value(&self) -> Option<u32>
Get the min_responses value, if this is a min_responses annotation.
Sourcepub fn is_custom_key(&self, expected_key: &str) -> bool
pub fn is_custom_key(&self, expected_key: &str) -> bool
Check if this is a custom annotation with the given key.
Sourcepub fn custom_value(&self, expected_key: &str) -> Option<&str>
pub fn custom_value(&self, expected_key: &str) -> Option<&str>
Get the custom value if this is a custom annotation with the given key.
Trait Implementations§
Source§impl Clone for ProtocolAnnotation
impl Clone for ProtocolAnnotation
Source§fn clone(&self) -> ProtocolAnnotation
fn clone(&self) -> ProtocolAnnotation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more