pub enum Driver {
Tcp(GenericDriver<TcpStream>),
Dynamic(GenericDriver<Box<dyn AsyncIoDyn + Send>>),
}
Expand description
async driver of Client
it handles IO and emit server sent message that do not belong to any query with AsyncLendingIterator
trait impl.
§Examples
use std::future::IntoFuture;
use xitca_postgres::{iter::AsyncLendingIterator, Driver};
// drive the client and listen to server notify at the same time.
fn drive_with_server_notify(mut drv: Driver) {
tokio::spawn(async move {
while let Ok(Some(msg)) = drv.try_next().await {
// *Note:
// handle message must be non-blocking to prevent starvation of driver.
}
});
}
// drive client without handling notify.
fn drive_only(drv: Driver) {
tokio::spawn(drv.into_future());
}
§Lifetime
Driver and Client
have a dependent lifetime where either side can trigger the other part to shutdown.
From Driver side it’s in the form of dropping ownership.
§Examples
// connect to a database
let (cli, drv) = Postgres::new(cfg).connect().await?;
// drop driver
drop(drv);
// client will always return error when it's driver is gone.
let e = "SELECT 1".query(&cli).await.unwrap_err();
// a shortcut method can be used to determine if the error is caused by a shutdown driver.
assert!(e.is_driver_down());
Variants§
Trait Implementations§
Source§impl AsyncLendingIterator for Driver
impl AsyncLendingIterator for Driver
Source§impl IntoFuture for Driver
impl IntoFuture for Driver
Source§type IntoFuture = Pin<Box<dyn Future<Output = <Driver as IntoFuture>::Output> + Send>>
type IntoFuture = Pin<Box<dyn Future<Output = <Driver as IntoFuture>::Output> + Send>>
Which kind of future are we turning this into?
Source§fn into_future(self) -> Self::IntoFuture
fn into_future(self) -> Self::IntoFuture
Creates a future from a value. Read more
Auto Trait Implementations§
impl !Freeze for Driver
impl !RefUnwindSafe for Driver
impl Send for Driver
impl !Sync for Driver
impl Unpin for Driver
impl !UnwindSafe for Driver
Blanket Implementations§
Source§impl<I> AsyncLendingIteratorExt for Iwhere
I: AsyncLendingIterator,
impl<I> AsyncLendingIteratorExt for Iwhere
I: AsyncLendingIterator,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more