pub struct RequestTable { /* private fields */ }Expand description
Tracks in-flight requests for a single connection.
Each accepted connection (UDS or WebSocket) has its own RequestTable.
Request IDs are scoped to the connection: the same ID on two different
connections refers to two independent requests.
§Examples
use nerve_ipc_core::RequestTable;
use nerve_protocol::types::RequestId;
let mut table = RequestTable::new();
let id = RequestId(42);
// 1. Register when the request begins.
assert!(table.insert(id));
// 2. Check before producing results.
assert!(!table.is_cancelled(id));
// 3. Mark cancelled when a Cancel message arrives.
table.cancel(id);
assert!(table.is_cancelled(id));
assert!(!table.is_active(id));
// 4. Remove on completion.
table.remove(id);
assert!(table.is_empty());Implementations§
Source§impl RequestTable
impl RequestTable
Sourcepub fn insert(&mut self, request_id: RequestId) -> bool
pub fn insert(&mut self, request_id: RequestId) -> bool
Register a new request as RequestState::Active.
Returns false if request_id is already present; the existing entry
is left unchanged in that case.
Sourcepub fn cancel(&mut self, request_id: RequestId) -> bool
pub fn cancel(&mut self, request_id: RequestId) -> bool
Mark an existing request as RequestState::Cancelled.
Returns false if request_id is not present in the table.
Sourcepub fn is_cancelled(&self, request_id: RequestId) -> bool
pub fn is_cancelled(&self, request_id: RequestId) -> bool
Returns true if the request has been cancelled.
Sourcepub fn remove(&mut self, request_id: RequestId)
pub fn remove(&mut self, request_id: RequestId)
Remove the request from the table, regardless of its state.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of requests currently tracked (active and cancelled combined).
Sourcepub fn contains(&self, request_id: RequestId) -> bool
pub fn contains(&self, request_id: RequestId) -> bool
Returns true if request_id is present in the table, regardless of
its state.
Sourcepub fn is_active(&self, request_id: RequestId) -> bool
pub fn is_active(&self, request_id: RequestId) -> bool
Returns true if the request is present and in the
RequestState::Active state.