Skip to content

Is it possible to implement a real Stream? #166

@nappa85

Description

@nappa85

To make a non-panicking collect, with the actual code I have to do something like

async fn query<T: FromRow, E: From<FromRowError> + From<Error>>(conn: &mut Conn, query: &str) -> Result<Vec<T>, E> {
  conn.query_iter(query).await?
    .try_collect::<T>().await?
    .into_iter().collect::<Result<Vec<T>, E>>()
}

(this is only for example purposes, could contains errors)

This means allocating the entire resultset even if every single row is an error, or having to implement a wrapper to use next() as a Stream...
Wouldn't be possible, for example, to add an impl of futures_core::Stream that is the same used by tokio-stream and it seems to be a standard de-facto?
If you prefer, under a feature, so it wouldn't be default for everyone.

I can do the PR if you want

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