Skip to content

Commit

Permalink
doc fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeshadow committed Mar 15, 2024
1 parent 4ae00f6 commit 60ede0b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion postgres/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(super) async fn connect(cfg: &mut Config) -> Result<(Client, Driver), Error>
}

/// async driver of [Client](crate::Client).
/// it handles IO and emit server sent message that do not belong to any query with [AsyncIterator]
/// it handles IO and emit server sent message that do not belong to any query with [AsyncLendingIterator]
/// trait impl.
///
/// # Examples:
Expand Down
24 changes: 23 additions & 1 deletion postgres/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ use crate::driver::codec::Request;

use super::from_sql::FromSqlError;

/// public facing error type. providing basic format and display based error handling.
/// for typed based error handling runtime type cast is needed with the help of other
/// public error types offered by this module.
///
/// # Example
/// ```rust
/// use xitca_postgres::error::{DriverDown, Error};
///
/// fn is_driver_down(e: Error) -> bool {
/// // downcast error to DriverDown error type to check if client driver is gone.
/// e.downcast_ref::<DriverDown>().is_some()
/// }
/// ```
pub struct Error(Box<dyn error::Error + Send + Sync>);

impl Error {
Expand Down Expand Up @@ -63,6 +76,14 @@ impl error::Error for Error {
}
}

/// error indicate [Client]'s [Driver] is dropped and can't be accessed anymore.
///
/// the field inside error contains the raw bytes buffer of query message that are ready to be
/// sent to the [Driver] for transporting. It's possible to construct a new [Client] and [Driver]
/// pair where the bytes buffer could be reused for graceful retry of previous failed queries.
///
/// [Client]: crate::client::Client
/// [Driver]: crate::driver::Driver
#[derive(Default)]
pub struct DriverDown(pub BytesMut);

Expand All @@ -74,7 +95,7 @@ impl fmt::Debug for DriverDown {

impl fmt::Display for DriverDown {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Driver is down")
f.write_str("Driver is dropped and unaccessible.")
}
}

Expand Down Expand Up @@ -138,6 +159,7 @@ impl From<SendError<Request>> for Error {
}
}

/// error happens when library user failed to provide valid authentication info to database server.
#[derive(Debug)]
pub enum AuthenticationError {
MissingUserName,
Expand Down

0 comments on commit 60ede0b

Please sign in to comment.