zero_postgres/state/
mod.rs

1//! Sans-I/O state machines for PostgreSQL protocol.
2//!
3//! These state machines handle the protocol logic without performing any I/O.
4//! They produce `Action` values that tell the caller what to do next.
5
6pub mod action;
7pub mod batch_prepare;
8pub mod connection;
9pub mod extended;
10pub mod simple_query;
11
12pub use action::{Action, AsyncMessage};
13pub use connection::ConnectionStateMachine;
14pub use extended::ExtendedQueryStateMachine;
15pub use simple_query::SimpleQueryStateMachine;
16
17use crate::buffer_set::BufferSet;
18use crate::error::Result;
19use crate::protocol::types::TransactionStatus;
20
21/// Trait for state machines that can be driven by a connection.
22pub trait StateMachine {
23    /// Process input and return the next action to perform.
24    ///
25    /// The driver should:
26    /// 1. Call `step()` to get the next action
27    /// 2. Perform the action (read/write/tls handshake)
28    /// 3. Repeat until `Action::Finished`
29    ///
30    /// When `Action::Write` is returned, the driver should write
31    /// `buffer_set.write_buffer` to the socket.
32    fn step(&mut self, buffer_set: &mut BufferSet) -> Result<Action>;
33
34    /// Get the transaction status from the final ReadyForQuery.
35    fn transaction_status(&self) -> TransactionStatus;
36}