Enum Driver

Source
pub enum Driver {
    Tcp(GenericDriver<TcpStream>),
    Dynamic(GenericDriver<Box<dyn AsyncIoDyn + Send>>),
    Unix(GenericDriver<UnixStream>),
}
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§

§

Tcp(GenericDriver<TcpStream>)

§

Dynamic(GenericDriver<Box<dyn AsyncIoDyn + Send>>)

§

Unix(GenericDriver<UnixStream>)

Trait Implementations§

Source§

impl AsyncLendingIterator for Driver

Source§

type Ok<'i> = Message where Self: 'i

Source§

type Err = Error

Source§

async fn try_next(&mut self) -> Result<Option<Self::Ok<'_>>, Self::Err>

Source§

fn size_hint(&self) -> (usize, Option<usize>)

Source§

impl IntoFuture for Driver

Source§

type Output = Result<(), Error>

The output that the future will produce on completion.
Source§

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

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<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<I> AsyncLendingIteratorExt for I

Source§

fn map_ok<F, O>(self, func: F) -> MapOk<Self, F>
where F: Fn(Self::Ok<'_>) -> O, Self: Sized,

Source§

fn try_collect<T>(self) -> impl Future<Output = Result<T, Self::Err>> + Send
where T: Default + for<'i> Extend<Self::Ok<'i>> + Send, Self: Send + Sized,

Source§

fn try_collect_into<T>( self, collection: T, ) -> impl Future<Output = Result<T, Self::Err>> + Send
where T: for<'i> Extend<Self::Ok<'i>> + Send, Self: Send + Sized,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V