Skip to content

Export Protocol and ConnectionLike #48

@xNxExOx

Description

@xNxExOx

I need these to be able to do:

extern crate mysql_async as my;
use my::{QueryResult, Protocol, ConnectionLike};
use my::prelude::FromRow;
use tokio_async_await::compat::forward::IntoAwaitable;

pub async fn get_all_results<TupleType, T, P>(result : QueryResult<T, P>) -> Result<Vec<TupleType>, my::error::Error>
    where TupleType: FromRow + Send + 'static,
          P: Protocol + Send + 'static,
          T: ConnectionLike + Sized + Send + 'static,  {
    let mut fut = result.collect();
    let (_, data) :(_, Vec<TupleType>) = match await!(fut.into_awaitable()) {
        Ok(r) => r,
        Err(e) => {return Err(e);}
    };
    Ok(data)
}

pub async fn get_single_result<TupleType, T, P>(result : QueryResult<T, P>) -> Result<TupleType, my::error::Error>
    where TupleType: FromRow + Send + 'static,
          P: Protocol + Send + 'static,
          T: ConnectionLike + Sized + Send + 'static,  {
    let mut data : Vec<TupleType> = await!(get_all_results(result))?;
    if data.len() != 1 {
        Err(my::error::Error::Io(std::io::Error::from(std::io::ErrorKind::InvalidData)))
    }else {
        Ok(data.remove(0))
    }
}```
right now I need to use modified version to to make them public exported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions