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