Skip to main content

rootle_kernel/
request.rs

1//! A request accepts partial replies until exactly one terminal reply lands.
2
3#[derive(Clone, Copy)]
4pub enum Phase {
5    Idle,
6    Loading,
7    Ready,
8    Failed,
9}
10
11#[derive(Clone, Copy)]
12pub enum Reply {
13    Partial,
14    Complete,
15    Failed,
16}
17
18/// Decide acceptance and the next phase in one operation. Rejection leaves
19/// the caller's state untouched. Payload identity is additionally checked by
20/// the adapter; generation equality alone must never override that check.
21pub fn accept(current: u64, phase: Phase, incoming: u64, reply: Reply) -> Option<Phase> {
22    if current != incoming {
23        return None;
24    }
25    match phase {
26        Phase::Loading => Some(match reply {
27            Reply::Partial => Phase::Loading,
28            Reply::Complete => Phase::Ready,
29            Reply::Failed => Phase::Failed,
30        }),
31        Phase::Idle | Phase::Ready | Phase::Failed => None,
32    }
33}