toasty_core/error/
read_only_transaction.rs

1use super::Error;
2
3#[derive(Debug)]
4pub(super) struct ReadOnlyTransaction {
5    message: Box<str>,
6}
7
8impl std::error::Error for ReadOnlyTransaction {}
9
10impl core::fmt::Display for ReadOnlyTransaction {
11    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
12        write!(f, "read-only transaction: {}", self.message)
13    }
14}
15
16impl Error {
17    /// Creates a read-only transaction error.
18    ///
19    /// Returned when a write operation is attempted inside a read-only
20    /// transaction (e.g. PostgreSQL SQLSTATE 25006, MySQL error 1792).
21    pub fn read_only_transaction(message: impl Into<String>) -> Error {
22        Error::from(super::ErrorKind::ReadOnlyTransaction(ReadOnlyTransaction {
23            message: message.into().into(),
24        }))
25    }
26
27    /// Returns `true` if this error is a read-only transaction error.
28    pub fn is_read_only_transaction(&self) -> bool {
29        matches!(self.kind(), super::ErrorKind::ReadOnlyTransaction(_))
30    }
31}